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 <milas.bowman@docker.com>
This commit is contained in:
Milas Bowman 2023-07-17 17:32:11 -04:00 committed by Nicolas De loof
parent 6ff15d9472
commit 3bc871e64b
15 changed files with 48 additions and 7 deletions

View File

@ -35,6 +35,12 @@ func TestLocalComposeExec(t *testing.T) {
return ret return ret
} }
cleanup := func() {
c.RunDockerComposeCmd(t, cmdArgs("down", "--timeout=0")...)
}
cleanup()
t.Cleanup(cleanup)
c.RunDockerComposeCmd(t, cmdArgs("up", "-d")...) c.RunDockerComposeCmd(t, cmdArgs("up", "-d")...)
t.Run("exec true", func(t *testing.T) { t.Run("exec true", func(t *testing.T) {

View File

@ -281,8 +281,12 @@ func TestStopWithDependenciesAttached(t *testing.T) {
const projectName = "compose-e2e-stop-with-deps" const projectName = "compose-e2e-stop-with-deps"
c := NewParallelCLI(t, WithEnv("COMMAND=echo hello")) c := NewParallelCLI(t, WithEnv("COMMAND=echo hello"))
t.Run("up", func(t *testing.T) { cleanup := func() {
c.RunDockerComposeCmd(t, "-p", projectName, "down", "--remove-orphans", "--timeout=0")
}
cleanup()
t.Cleanup(cleanup)
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/dependencies/compose.yaml", "-p", projectName, "up", "--attach-dependencies", "foo") res := c.RunDockerComposeCmd(t, "-f", "./fixtures/dependencies/compose.yaml", "-p", projectName, "up", "--attach-dependencies", "foo")
res.Assert(t, icmd.Expected{Out: "exited with code 0"}) res.Assert(t, icmd.Expected{Out: "exited with code 0"})
})
} }

View File

@ -51,8 +51,18 @@ func TestUpExitCodeFrom(t *testing.T) {
c := NewParallelCLI(t) c := NewParallelCLI(t)
const projectName = "e2e-exit-code-from" const projectName = "e2e-exit-code-from"
res := c.RunDockerComposeCmdNoCheck(t, "-f", "fixtures/start-fail/start-depends_on-long-lived.yaml", "--project-name", projectName, "up", "--exit-code-from=failure", "failure")
res.Assert(t, icmd.Expected{ExitCode: 42})
c.RunDockerComposeCmd(t, "--project-name", projectName, "down", "--remove-orphans")
}
func TestUpExitCodeFromContainerKilled(t *testing.T) {
c := NewParallelCLI(t)
const projectName = "e2e-exit-code-from-kill"
res := c.RunDockerComposeCmdNoCheck(t, "-f", "fixtures/start-fail/start-depends_on-long-lived.yaml", "--project-name", projectName, "up", "--exit-code-from=test") res := c.RunDockerComposeCmdNoCheck(t, "-f", "fixtures/start-fail/start-depends_on-long-lived.yaml", "--project-name", projectName, "up", "--exit-code-from=test")
res.Assert(t, icmd.Expected{ExitCode: 137}) res.Assert(t, icmd.Expected{ExitCode: 143})
c.RunDockerComposeCmd(t, "--project-name", projectName, "down", "--remove-orphans") c.RunDockerComposeCmd(t, "--project-name", projectName, "down", "--remove-orphans")
} }

View File

@ -1,10 +1,12 @@
services: services:
base: base:
image: base image: base
init: true
build: build:
context: . context: .
dockerfile: base.dockerfile dockerfile: base.dockerfile
service: service:
init: true
depends_on: depends_on:
- base - base
build: build:

View File

@ -4,6 +4,7 @@ services:
command: echo 'hello world' command: echo 'hello world'
longrunning: longrunning:
image: alpine image: alpine
init: true
depends_on: depends_on:
oneshot: oneshot:
condition: service_completed_successfully condition: service_completed_successfully

View File

@ -3,6 +3,7 @@ services:
my-service: my-service:
image: alpine image: alpine
command: tail -f /dev/null command: tail -f /dev/null
init: true
depends_on: depends_on:
nginx: {condition: service_healthy} nginx: {condition: service_healthy}

View File

@ -1,6 +1,7 @@
services: services:
foo: foo:
image: alpine image: alpine
init: true
entrypoint: ["sleep", "600"] entrypoint: ["sleep", "600"]
networks: networks:
default: default:

View File

@ -1,6 +1,7 @@
services: services:
ping: ping:
image: alpine image: alpine
init: true
command: ping localhost -c ${REPEAT:-1} command: ping localhost -c ${REPEAT:-1}
hello: hello:
image: alpine image: alpine

View File

@ -6,12 +6,14 @@ services:
- MYSQL_ALLOW_EMPTY_PASSWORD=yes - MYSQL_ALLOW_EMPTY_PASSWORD=yes
db: db:
image: gtardif/sentences-db image: gtardif/sentences-db
init: true
networks: networks:
- dbnet - dbnet
- closesnetworkname1 - closesnetworkname1
- closesnetworkname2 - closesnetworkname2
words: words:
image: gtardif/sentences-api image: gtardif/sentences-api
init: true
ports: ports:
- "8080:8080" - "8080:8080"
networks: networks:
@ -19,6 +21,7 @@ services:
- servicenet - servicenet
web: web:
image: gtardif/sentences-web image: gtardif/sentences-web
init: true
ports: ports:
- "80:80" - "80:80"
labels: labels:

View File

@ -1,12 +1,14 @@
services: services:
with-restart: with-restart:
image: alpine image: alpine
init: true
command: tail -f /dev/null command: tail -f /dev/null
depends_on: depends_on:
nginx: {condition: service_healthy, restart: true} nginx: {condition: service_healthy, restart: true}
no-restart: no-restart:
image: alpine image: alpine
init: true
command: tail -f /dev/null command: tail -f /dev/null
depends_on: depends_on:
nginx: { condition: service_healthy } nginx: { condition: service_healthy }

View File

@ -1,4 +1,5 @@
services: services:
restart: restart:
image: alpine image: alpine
init: true
command: ash -c "if [[ -f /tmp/restart.lock ]] ; then sleep infinity; else touch /tmp/restart.lock; fi" command: ash -c "if [[ -f /tmp/restart.lock ]] ; then sleep infinity; else touch /tmp/restart.lock; fi"

View File

@ -1,12 +1,15 @@
services: services:
db: db:
image: gtardif/sentences-db image: gtardif/sentences-db
init: true
words: words:
image: gtardif/sentences-api image: gtardif/sentences-api
init: true
ports: ports:
- "95:8080" - "95:8080"
web: web:
image: gtardif/sentences-web image: gtardif/sentences-web
init: true
ports: ports:
- "90:80" - "90:80"
labels: labels:

View File

@ -1,6 +1,7 @@
services: services:
fail: fail:
image: alpine image: alpine
init: true
command: sleep infinity command: sleep infinity
healthcheck: healthcheck:
test: "false" test: "false"
@ -8,6 +9,7 @@ services:
retries: 3 retries: 3
depends: depends:
image: alpine image: alpine
init: true
command: sleep infinity command: sleep infinity
depends_on: depends_on:
fail: fail:

View File

@ -1,11 +1,14 @@
services: services:
safe: safe:
image: 'alpine' image: 'alpine'
init: true
command: ['/bin/sh', '-c', 'sleep infinity'] # never exiting command: ['/bin/sh', '-c', 'sleep infinity'] # never exiting
failure: failure:
image: 'alpine' image: 'alpine'
command: ['/bin/sh', '-c', 'sleep 2 ; echo "exiting" ; exit 42'] init: true
command: ['/bin/sh', '-c', 'sleep 1 ; echo "exiting with error" ; exit 42']
test: test:
image: 'alpine' image: 'alpine'
init: true
command: ['/bin/sh', '-c', 'sleep 99999 ; echo "tests are OK"'] # very long job command: ['/bin/sh', '-c', 'sleep 99999 ; echo "tests are OK"'] # very long job
depends_on: [safe] depends_on: [safe]

View File

@ -1,6 +1,7 @@
services: services:
stderr: stderr:
image: alpine image: alpine
init: true
command: /bin/ash /log_to_stderr.sh command: /bin/ash /log_to_stderr.sh
volumes: volumes:
- ./log_to_stderr.sh:/log_to_stderr.sh - ./log_to_stderr.sh:/log_to_stderr.sh