MCPcopy
hub / github.com/moby/moby / TestContainerStartOnDaemonRestart

Function TestContainerStartOnDaemonRestart

integration/container/daemon_linux_test.go:35–73  ·  view source on GitHub ↗

This is a regression test for #36145 It ensures that a container can be started when the daemon was improperly shutdown when the daemon is brought back up. The regression is due to improper error handling preventing a container from being restored and as such have the resources cleaned up. To test

(t *testing.T)

Source from the content-addressed store, hash-verified

33// the container process, then start dockerd back up and attempt to start the
34// container again.
35func TestContainerStartOnDaemonRestart(t *testing.T) {
36 skip.If(t, testEnv.IsRemoteDaemon, "cannot start daemon on remote test run")
37 skip.If(t, testEnv.DaemonInfo.OSType == "windows")
38 skip.If(t, testEnv.IsRootless)
39 t.Parallel()
40
41 ctx := testutil.StartSpan(baseContext, t)
42
43 d := daemon.New(t)
44 d.StartWithBusybox(ctx, t, "--iptables=false", "--ip6tables=false")
45 defer d.Stop(t)
46
47 c := d.NewClientT(t)
48
49 cID := container.Create(ctx, t, c)
50 defer c.ContainerRemove(ctx, cID, client.ContainerRemoveOptions{Force: true})
51
52 _, err := c.ContainerStart(ctx, cID, client.ContainerStartOptions{})
53 assert.Check(t, err, "error starting test container")
54
55 inspect, err := c.ContainerInspect(ctx, cID, client.ContainerInspectOptions{})
56 assert.Check(t, err, "error getting inspect data")
57
58 ppid := getContainerdShimPid(t, inspect.Container)
59
60 err = d.Kill()
61 assert.Check(t, err, "failed to kill test daemon")
62
63 err = unix.Kill(inspect.Container.State.Pid, unix.SIGKILL)
64 assert.Check(t, err, "failed to kill container process")
65
66 err = unix.Kill(ppid, unix.SIGKILL)
67 assert.Check(t, err, "failed to kill containerd-shim")
68
69 d.Start(t, "--iptables=false", "--ip6tables=false")
70
71 _, err = c.ContainerStart(ctx, cID, client.ContainerStartOptions{})
72 assert.Check(t, err, "failed to start test container")
73}
74
75func getContainerdShimPid(t *testing.T, c containertypes.InspectResponse) int {
76 statB, err := os.ReadFile(fmt.Sprintf("/proc/%d/stat", c.State.Pid))

Callers

nothing calls this directly

Calls 13

StartSpanFunction · 0.92
NewFunction · 0.92
CreateFunction · 0.92
getContainerdShimPidFunction · 0.85
StartWithBusyboxMethod · 0.80
NewClientTMethod · 0.80
CheckMethod · 0.80
ContainerRemoveMethod · 0.65
ContainerStartMethod · 0.65
ContainerInspectMethod · 0.65
KillMethod · 0.65
StartMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…