Skip to content

Commit 3bc871e

Browse files
milasndeloof
authored andcommitted
test: speed up the e2e test suite
Lots of our phony Compose files launch pointless long-lived processes so we can assert on state. However, this means they often don't respond well to signals on their own, requiring Compose to timeout and kill them when doing a `down`. Add in lots of `init: true` where appropriate so that we don't block for no reason while running E2E tests all over the place. Additionally, a couple tests have gotten a cleanup so they don't leave behind containers. I still want to build this into the framework in the future, but this is easier for the moment and won't cause any trouble in the future. Signed-off-by: Milas Bowman <[email protected]>
1 parent 6ff15d9 commit 3bc871e

File tree

15 files changed

+48
-7
lines changed

15 files changed

+48
-7
lines changed

pkg/e2e/compose_exec_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ func TestLocalComposeExec(t *testing.T) {
3535
return ret
3636
}
3737

38+
cleanup := func() {
39+
c.RunDockerComposeCmd(t, cmdArgs("down", "--timeout=0")...)
40+
}
41+
cleanup()
42+
t.Cleanup(cleanup)
43+
3844
c.RunDockerComposeCmd(t, cmdArgs("up", "-d")...)
3945

4046
t.Run("exec true", func(t *testing.T) {

pkg/e2e/compose_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,12 @@ func TestStopWithDependenciesAttached(t *testing.T) {
281281
const projectName = "compose-e2e-stop-with-deps"
282282
c := NewParallelCLI(t, WithEnv("COMMAND=echo hello"))
283283

284-
t.Run("up", func(t *testing.T) {
285-
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/dependencies/compose.yaml", "-p", projectName, "up", "--attach-dependencies", "foo")
286-
res.Assert(t, icmd.Expected{Out: "exited with code 0"})
287-
})
284+
cleanup := func() {
285+
c.RunDockerComposeCmd(t, "-p", projectName, "down", "--remove-orphans", "--timeout=0")
286+
}
287+
cleanup()
288+
t.Cleanup(cleanup)
289+
290+
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/dependencies/compose.yaml", "-p", projectName, "up", "--attach-dependencies", "foo")
291+
res.Assert(t, icmd.Expected{Out: "exited with code 0"})
288292
}

pkg/e2e/compose_up_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,18 @@ func TestUpExitCodeFrom(t *testing.T) {
5151
c := NewParallelCLI(t)
5252
const projectName = "e2e-exit-code-from"
5353

54+
res := c.RunDockerComposeCmdNoCheck(t, "-f", "fixtures/start-fail/start-depends_on-long-lived.yaml", "--project-name", projectName, "up", "--exit-code-from=failure", "failure")
55+
res.Assert(t, icmd.Expected{ExitCode: 42})
56+
57+
c.RunDockerComposeCmd(t, "--project-name", projectName, "down", "--remove-orphans")
58+
}
59+
60+
func TestUpExitCodeFromContainerKilled(t *testing.T) {
61+
c := NewParallelCLI(t)
62+
const projectName = "e2e-exit-code-from-kill"
63+
5464
res := c.RunDockerComposeCmdNoCheck(t, "-f", "fixtures/start-fail/start-depends_on-long-lived.yaml", "--project-name", projectName, "up", "--exit-code-from=test")
55-
res.Assert(t, icmd.Expected{ExitCode: 137})
65+
res.Assert(t, icmd.Expected{ExitCode: 143})
5666

5767
c.RunDockerComposeCmd(t, "--project-name", projectName, "down", "--remove-orphans")
5868
}

pkg/e2e/fixtures/build-dependencies/compose.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
services:
22
base:
33
image: base
4+
init: true
45
build:
56
context: .
67
dockerfile: base.dockerfile
78
service:
9+
init: true
810
depends_on:
911
- base
1012
build:

pkg/e2e/fixtures/dependencies/deps-completed-successfully.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ services:
44
command: echo 'hello world'
55
longrunning:
66
image: alpine
7+
init: true
78
depends_on:
89
oneshot:
910
condition: service_completed_successfully

pkg/e2e/fixtures/dependencies/recreate-no-deps.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ services:
33
my-service:
44
image: alpine
55
command: tail -f /dev/null
6+
init: true
67
depends_on:
78
nginx: {condition: service_healthy}
89

pkg/e2e/fixtures/ipam/compose.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
services:
22
foo:
33
image: alpine
4+
init: true
45
entrypoint: ["sleep", "600"]
56
networks:
67
default:
@@ -9,4 +10,4 @@ networks:
910
default:
1011
ipam:
1112
config:
12-
- subnet: 10.1.0.0/16
13+
- subnet: 10.1.0.0/16

pkg/e2e/fixtures/logs-test/compose.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
services:
22
ping:
33
image: alpine
4+
init: true
45
command: ping localhost -c ${REPEAT:-1}
56
hello:
67
image: alpine

pkg/e2e/fixtures/network-test/compose.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,22 @@ services:
66
- MYSQL_ALLOW_EMPTY_PASSWORD=yes
77
db:
88
image: gtardif/sentences-db
9+
init: true
910
networks:
1011
- dbnet
1112
- closesnetworkname1
1213
- closesnetworkname2
1314
words:
1415
image: gtardif/sentences-api
16+
init: true
1517
ports:
1618
- "8080:8080"
1719
networks:
1820
- dbnet
1921
- servicenet
2022
web:
2123
image: gtardif/sentences-web
24+
init: true
2225
ports:
2326
- "80:80"
2427
labels:

pkg/e2e/fixtures/restart-test/compose-depends-on.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
services:
22
with-restart:
33
image: alpine
4+
init: true
45
command: tail -f /dev/null
56
depends_on:
67
nginx: {condition: service_healthy, restart: true}
78

89
no-restart:
910
image: alpine
11+
init: true
1012
command: tail -f /dev/null
1113
depends_on:
1214
nginx: { condition: service_healthy }

0 commit comments

Comments
 (0)