TestPublishedPortAlreadyInUse checks that a container that can't start because of one its published port being already in use doesn't end up triggering the restart loop. Regression test for: https://github.com/moby/moby/issues/49501
(t *testing.T)
| 514 | // |
| 515 | // Regression test for: https://github.com/moby/moby/issues/49501 |
| 516 | func TestPublishedPortAlreadyInUse(t *testing.T) { |
| 517 | ctx := setupTest(t) |
| 518 | apiClient := testEnv.APIClient() |
| 519 | mappedPort := networktypes.MustParsePort("80/tcp") |
| 520 | |
| 521 | ctr1 := ctr.Run(ctx, t, apiClient, |
| 522 | ctr.WithCmd("top"), |
| 523 | ctr.WithExposedPorts("80/tcp"), |
| 524 | ctr.WithPortMap(networktypes.PortMap{mappedPort: {{HostPort: "8000"}}})) |
| 525 | defer ctr.Remove(ctx, t, apiClient, ctr1, client.ContainerRemoveOptions{Force: true}) |
| 526 | |
| 527 | ctr2 := ctr.Create(ctx, t, apiClient, |
| 528 | ctr.WithCmd("top"), |
| 529 | ctr.WithRestartPolicy(containertypes.RestartPolicyAlways), |
| 530 | ctr.WithExposedPorts("80/tcp"), |
| 531 | ctr.WithPortMap(networktypes.PortMap{mappedPort: {{HostPort: "8000"}}})) |
| 532 | defer ctr.Remove(ctx, t, apiClient, ctr2, client.ContainerRemoveOptions{Force: true}) |
| 533 | |
| 534 | _, err := apiClient.ContainerStart(ctx, ctr2, client.ContainerStartOptions{}) |
| 535 | assert.Assert(t, is.ErrorContains(err, "failed to set up container networking")) |
| 536 | |
| 537 | inspect, err := apiClient.ContainerInspect(ctx, ctr2, client.ContainerInspectOptions{}) |
| 538 | assert.NilError(t, err) |
| 539 | assert.Check(t, is.Equal(inspect.Container.State.Status, containertypes.StateCreated)) |
| 540 | } |
| 541 | |
| 542 | // TestAllPortMappingsAreReturned check that dual-stack ports mapped through |
| 543 | // different networks are correctly reported as dual-stakc. |
nothing calls this directly
no test coverage detected
searching dependent graphs…