MCPcopy
hub / github.com/docker/compose / TestUpDependenciesNotStopped

Function TestUpDependenciesNotStopped

pkg/e2e/up_test.go:47–107  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

45}
46
47func TestUpDependenciesNotStopped(t *testing.T) {
48 c := NewParallelCLI(t, WithEnv(
49 "COMPOSE_PROJECT_NAME=up-deps-stop",
50 ))
51
52 reset := func() {
53 c.RunDockerComposeCmdNoCheck(t, "down", "-t=0", "--remove-orphans", "-v")
54 }
55 reset()
56 t.Cleanup(reset)
57
58 t.Log("Launching orphan container (background)")
59 c.RunDockerComposeCmd(t,
60 "-f=./fixtures/ups-deps-stop/orphan.yaml",
61 "up",
62 "--wait",
63 "--detach",
64 "orphan",
65 )
66 RequireServiceState(t, c, "orphan", "running")
67
68 t.Log("Launching app container with implicit dependency")
69 upOut := &utils.SafeBuffer{}
70 testCmd := c.NewDockerComposeCmd(t,
71 "-f=./fixtures/ups-deps-stop/compose.yaml",
72 "up",
73 "--menu=false",
74 "app",
75 )
76
77 ctx, cancel := context.WithTimeout(t.Context(), 15*time.Second)
78 t.Cleanup(cancel)
79
80 cmd, err := StartWithNewGroupID(ctx, testCmd, upOut, nil)
81 assert.NilError(t, err, "Failed to run compose up")
82
83 t.Log("Waiting for containers to be in running state")
84 upOut.RequireEventuallyContains(t, "hello app")
85 RequireServiceState(t, c, "app", "running")
86 RequireServiceState(t, c, "dependency", "running")
87
88 t.Log("Simulating Ctrl-C")
89 assert.NilError(t, syscall.Kill(-cmd.Process.Pid, syscall.SIGINT),
90 "Failed to send SIGINT to compose up process")
91
92 t.Log("Waiting for `compose up` to exit")
93 err = cmd.Wait()
94 if err != nil {
95 var exitErr *exec.ExitError
96 errors.As(err, &exitErr)
97 if exitErr.ExitCode() == -1 {
98 t.Fatalf("`compose up` was killed: %v", err)
99 }
100 assert.Equal(t, 130, exitErr.ExitCode())
101 }
102
103 RequireServiceState(t, c, "app", "exited")
104 // dependency should still be running

Callers

nothing calls this directly

Calls 12

NewParallelCLIFunction · 0.85
WithEnvFunction · 0.85
RequireServiceStateFunction · 0.85
StartWithNewGroupIDFunction · 0.85
RunDockerComposeCmdMethod · 0.80
NewDockerComposeCmdMethod · 0.80
ExitCodeMethod · 0.80
LogMethod · 0.65
KillMethod · 0.65
WaitMethod · 0.65

Tested by

no test coverage detected