MCPcopy
hub / github.com/moby/moby / TestPublishedPortAlreadyInUse

Function TestPublishedPortAlreadyInUse

integration/network/bridge/bridge_linux_test.go:516–540  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

514//
515// Regression test for: https://github.com/moby/moby/issues/49501
516func 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.

Callers

nothing calls this directly

Calls 9

APIClientMethod · 0.80
CheckMethod · 0.80
EqualMethod · 0.80
setupTestFunction · 0.70
RunMethod · 0.65
RemoveMethod · 0.65
CreateMethod · 0.65
ContainerStartMethod · 0.65
ContainerInspectMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…