11/*
2- Copyright 2020 Docker Compose CLI authors
2+ Copyright 2022 Docker Compose CLI authors
33
44 Licensed under the Apache License, Version 2.0 (the "License");
55 you may not use this file except in compliance with the License.
1717package e2e
1818
1919import (
20+ "context"
21+ "os/exec"
22+ "syscall"
2023 "testing"
24+ "time"
2125
26+ "github.com/stretchr/testify/assert"
27+ "github.com/stretchr/testify/require"
2228 "gotest.tools/v3/icmd"
2329)
2430
@@ -31,3 +37,69 @@ func TestUpServiceUnhealthy(t *testing.T) {
3137
3238 c .RunDockerComposeCmd (t , "--project-name" , projectName , "down" )
3339}
40+
41+ func TestUpDependenciesNotStopped (t * testing.T ) {
42+ c := NewParallelCLI (t , WithEnv (
43+ "COMPOSE_PROJECT_NAME=up-deps-stop" ,
44+ ))
45+
46+ reset := func () {
47+ c .RunDockerComposeCmdNoCheck (t , "down" , "-t=0" , "--remove-orphans" , "-v" )
48+ }
49+ reset ()
50+ t .Cleanup (reset )
51+
52+ ctx , cancel := context .WithCancel (context .Background ())
53+ defer cancel ()
54+
55+ t .Log ("Launching orphan container (background)" )
56+ c .RunDockerComposeCmd (t ,
57+ "-f=./fixtures/ups-deps-stop/orphan.yaml" ,
58+ "up" ,
59+ "--wait" ,
60+ "--detach" ,
61+ "orphan" ,
62+ )
63+ RequireServiceState (t , c , "orphan" , "running" )
64+
65+ t .Log ("Launching app container with implicit dependency" )
66+ var upOut lockedBuffer
67+ var upCmd * exec.Cmd
68+ go func () {
69+ testCmd := c .NewDockerComposeCmd (t ,
70+ "-f=./fixtures/ups-deps-stop/compose.yaml" ,
71+ "up" ,
72+ "app" ,
73+ )
74+ cmd := exec .CommandContext (ctx , testCmd .Command [0 ], testCmd .Command [1 :]... )
75+ cmd .Env = testCmd .Env
76+ cmd .Stdout = & upOut
77+ cmd .SysProcAttr = & syscall.SysProcAttr {Setpgid : true }
78+
79+ assert .NoError (t , cmd .Start (), "Failed to run compose up" )
80+ upCmd = cmd
81+ }()
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+ require .NoError (t , syscall .Kill (- upCmd .Process .Pid , syscall .SIGINT ),
90+ "Failed to send SIGINT to compose up process" )
91+
92+ time .AfterFunc (5 * time .Second , cancel )
93+
94+ t .Log ("Waiting for `compose up` to exit" )
95+ err := upCmd .Wait ()
96+ if err != nil {
97+ exitErr := err .(* exec.ExitError )
98+ require .EqualValues (t , exitErr .ExitCode (), 130 )
99+ }
100+
101+ RequireServiceState (t , c , "app" , "exited" )
102+ // dependency should still be running
103+ RequireServiceState (t , c , "dependency" , "running" )
104+ RequireServiceState (t , c , "orphan" , "running" )
105+ }
0 commit comments