@@ -37,18 +37,26 @@ func TestComposeCancel(t *testing.T) {
37
37
c := NewParallelCLI (t )
38
38
39
39
t .Run ("metrics on cancel Compose build" , func (t * testing.T ) {
40
- c .RunDockerComposeCmd (t , "ls" )
41
- buildProjectPath := "fixtures/build-infinite/compose.yaml"
40
+ const buildProjectPath = "fixtures/build-infinite/compose.yaml"
41
+
42
+ ctx , cancel := context .WithCancel (context .Background ())
43
+ defer cancel ()
42
44
43
45
// require a separate groupID from the process running tests, in order to simulate ctrl+C from a terminal.
44
46
// sending kill signal
45
- stdout := & utils.SafeBuffer {}
46
- stderr := & utils. SafeBuffer {}
47
- cmd , err := StartWithNewGroupID ( context . Background () ,
47
+ var stdout , stderr utils.SafeBuffer
48
+ cmd , err := StartWithNewGroupID (
49
+ ctx ,
48
50
c .NewDockerComposeCmd (t , "-f" , buildProjectPath , "build" , "--progress" , "plain" ),
49
- stdout ,
50
- stderr )
51
+ & stdout ,
52
+ & stderr ,
53
+ )
51
54
assert .NilError (t , err )
55
+ processDone := make (chan error , 1 )
56
+ go func () {
57
+ defer close (processDone )
58
+ processDone <- cmd .Wait ()
59
+ }()
52
60
53
61
c .WaitForCondition (t , func () (bool , string ) {
54
62
out := stdout .String ()
@@ -58,15 +66,21 @@ func TestComposeCancel(t *testing.T) {
58
66
errors )
59
67
}, 30 * time .Second , 1 * time .Second )
60
68
61
- err = syscall .Kill (- cmd .Process .Pid , syscall .SIGINT ) // simulate Ctrl-C : send signal to processGroup, children will have same groupId by default
69
+ // simulate Ctrl-C : send signal to processGroup, children will have same groupId by default
70
+ err = syscall .Kill (- cmd .Process .Pid , syscall .SIGINT )
62
71
assert .NilError (t , err )
63
72
64
- c .WaitForCondition (t , func () (bool , string ) {
65
- out := stdout .String ()
66
- errors := stderr .String ()
67
- return strings .Contains (out , "CANCELED" ), fmt .Sprintf ("'CANCELED' not found in : \n %s\n Stderr: \n %s\n " , out ,
68
- errors )
69
- }, 10 * time .Second , 1 * time .Second )
73
+ select {
74
+ case <- ctx .Done ():
75
+ t .Fatal ("test context canceled" )
76
+ case err := <- processDone :
77
+ // TODO(milas): Compose should really not return exit code 130 here,
78
+ // this is an old hack for the compose-cli wrapper
79
+ assert .Error (t , err , "exit status 130" ,
80
+ "STDOUT:\n %s\n STDERR:\n %s\n " , stdout .String (), stderr .String ())
81
+ case <- time .After (10 * time .Second ):
82
+ t .Fatal ("timeout waiting for Compose exit" )
83
+ }
70
84
})
71
85
}
72
86
0 commit comments