Skip to content

Commit 8dea7b5

Browse files
committed
test: fix process leak in wait e2e test
* Run `down` before and after test to not leave around containers * Kill the `wait` process that's waiting on `infinity` * NOTE: If the test is actually working, this should exit once the `down` happens, but this ensures that we kill everything we start I'd like to generalize more of this into the framework, but this is a quick fix to prevent filling up CI machines with tons of processes over time. Signed-off-by: Milas Bowman <[email protected]>
1 parent bc6ad2e commit 8dea7b5

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

pkg/e2e/wait_test.go

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,21 @@ import (
2121
"testing"
2222
"time"
2323

24+
"gotest.tools/v3/icmd"
25+
2426
"gotest.tools/v3/assert"
2527
)
2628

2729
func TestWaitOnFaster(t *testing.T) {
2830
const projectName = "e2e-wait-faster"
2931
c := NewParallelCLI(t)
3032

33+
cleanup := func() {
34+
c.RunDockerComposeCmd(t, "--project-name", projectName, "down", "--timeout=0", "--remove-orphans")
35+
}
36+
t.Cleanup(cleanup)
37+
cleanup()
38+
3139
c.RunDockerComposeCmd(t, "-f", "./fixtures/wait/compose.yaml", "--project-name", projectName, "up", "-d")
3240
c.RunDockerComposeCmd(t, "--project-name", projectName, "wait", "faster")
3341
}
@@ -36,6 +44,12 @@ func TestWaitOnSlower(t *testing.T) {
3644
const projectName = "e2e-wait-slower"
3745
c := NewParallelCLI(t)
3846

47+
cleanup := func() {
48+
c.RunDockerComposeCmd(t, "--project-name", projectName, "down", "--timeout=0", "--remove-orphans")
49+
}
50+
t.Cleanup(cleanup)
51+
cleanup()
52+
3953
c.RunDockerComposeCmd(t, "-f", "./fixtures/wait/compose.yaml", "--project-name", projectName, "up", "-d")
4054
c.RunDockerComposeCmd(t, "--project-name", projectName, "wait", "slower")
4155
}
@@ -44,12 +58,27 @@ func TestWaitOnInfinity(t *testing.T) {
4458
const projectName = "e2e-wait-infinity"
4559
c := NewParallelCLI(t)
4660

61+
cleanup := func() {
62+
c.RunDockerComposeCmd(t, "--project-name", projectName, "down", "--timeout=0", "--remove-orphans")
63+
}
64+
t.Cleanup(cleanup)
65+
cleanup()
66+
4767
c.RunDockerComposeCmd(t, "-f", "./fixtures/wait/compose.yaml", "--project-name", projectName, "up", "-d")
4868

69+
cmd := c.NewDockerComposeCmd(t, "--project-name", projectName, "wait", "infinity")
70+
r := icmd.StartCmd(cmd)
71+
assert.NilError(t, r.Error)
72+
t.Cleanup(func() {
73+
if r.Cmd.Process != nil {
74+
_ = r.Cmd.Process.Kill()
75+
}
76+
})
77+
4978
finished := make(chan struct{})
5079
ticker := time.NewTicker(7 * time.Second)
5180
go func() {
52-
c.RunDockerComposeCmd(t, "--project-name", projectName, "wait", "infinity")
81+
_ = r.Cmd.Wait()
5382
finished <- struct{}{}
5483
}()
5584

@@ -64,6 +93,12 @@ func TestWaitAndDrop(t *testing.T) {
6493
const projectName = "e2e-wait-and-drop"
6594
c := NewParallelCLI(t)
6695

96+
cleanup := func() {
97+
c.RunDockerComposeCmd(t, "--project-name", projectName, "down", "--timeout=0", "--remove-orphans")
98+
}
99+
t.Cleanup(cleanup)
100+
cleanup()
101+
67102
c.RunDockerComposeCmd(t, "-f", "./fixtures/wait/compose.yaml", "--project-name", projectName, "up", "-d")
68103
c.RunDockerComposeCmd(t, "--project-name", projectName, "wait", "--down-project", "faster")
69104

0 commit comments

Comments
 (0)