Skip to content

Commit 36bf0c4

Browse files
milasglours
authored andcommitted
chore(e2e): fix flaky cascade failure test
This was racy with the sleep, so the Compose file has been tweaked to make it pass reliably. Now, there's 3 services: * `running` - sleeps forever * `exit` - exits _successfully_ immediately * depends on `running` started * `fail` - exits _with error_ immediately * depends on `exit` succeeding Now, the test can ensure that the containers are all run/ started in the expected order the assertions will be reliable. Before, it was possible for `fail` to run & exit before `exit`, for example. The `running` service also ensures there's always at least one other "running" container when we do an abort. Signed-off-by: Milas Bowman <[email protected]>
1 parent 299fcd5 commit 36bf0c4

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

pkg/e2e/cascade_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ func TestCascadeStop(t *testing.T) {
3636
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/cascade/compose.yaml", "--project-name", projectName,
3737
"up", "--abort-on-container-exit")
3838
assert.Assert(t, strings.Contains(res.Combined(), "exit-1 exited with code 0"), res.Combined())
39+
// no --exit-code-from, so this is not an error
40+
assert.Equal(t, res.ExitCode, 0)
3941
}
4042

4143
func TestCascadeFail(t *testing.T) {
@@ -48,6 +50,7 @@ func TestCascadeFail(t *testing.T) {
4850
res := c.RunDockerComposeCmdNoCheck(t, "-f", "./fixtures/cascade/compose.yaml", "--project-name", projectName,
4951
"up", "--abort-on-container-failure")
5052
assert.Assert(t, strings.Contains(res.Combined(), "exit-1 exited with code 0"), res.Combined())
51-
assert.Assert(t, strings.Contains(res.Combined(), "fail-1 exited with code 1"), res.Combined())
52-
assert.Equal(t, res.ExitCode, 1)
53+
assert.Assert(t, strings.Contains(res.Combined(), "fail-1 exited with code 111"), res.Combined())
54+
// failing exit code should be propagated
55+
assert.Equal(t, res.ExitCode, 111)
5356
}

pkg/e2e/fixtures/cascade/compose.yaml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
services:
2+
running:
3+
image: alpine
4+
command: sleep infinity
5+
init: true
6+
27
exit:
38
image: alpine
49
command: /bin/true
10+
depends_on:
11+
running:
12+
condition: service_started
513

614
fail:
715
image: alpine
8-
command: sh -c "sleep 0.1 && /bin/false"
16+
command: sh -c "return 111"
17+
depends_on:
18+
exit:
19+
condition: service_completed_successfully

0 commit comments

Comments
 (0)