Skip to content

Commit 8fdd45c

Browse files
authored
chore(e2e): fix flaky test & standalone behavior (#11382)
1 parent a0954dc commit 8fdd45c

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

pkg/e2e/cancel_test.go

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,26 @@ func TestComposeCancel(t *testing.T) {
3737
c := NewParallelCLI(t)
3838

3939
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()
4244

4345
// require a separate groupID from the process running tests, in order to simulate ctrl+C from a terminal.
4446
// 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,
4850
c.NewDockerComposeCmd(t, "-f", buildProjectPath, "build", "--progress", "plain"),
49-
stdout,
50-
stderr)
51+
&stdout,
52+
&stderr,
53+
)
5154
assert.NilError(t, err)
55+
processDone := make(chan error, 1)
56+
go func() {
57+
defer close(processDone)
58+
processDone <- cmd.Wait()
59+
}()
5260

5361
c.WaitForCondition(t, func() (bool, string) {
5462
out := stdout.String()
@@ -58,15 +66,21 @@ func TestComposeCancel(t *testing.T) {
5866
errors)
5967
}, 30*time.Second, 1*time.Second)
6068

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)
6271
assert.NilError(t, err)
6372

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\nStderr: \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\nSTDERR:\n%s\n", stdout.String(), stderr.String())
81+
case <-time.After(10 * time.Second):
82+
t.Fatal("timeout waiting for Compose exit")
83+
}
7084
})
7185
}
7286

pkg/e2e/e2e_config_plugin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818

1919
package e2e
2020

21-
const composeStandaloneMode = true
21+
const composeStandaloneMode = false

0 commit comments

Comments
 (0)