From 8dea7b5cae96152040f2bdf9fdb9b6bb2429f117 Mon Sep 17 00:00:00 2001 From: Milas Bowman Date: Mon, 10 Jul 2023 08:38:04 -0400 Subject: [PATCH] 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 --- pkg/e2e/wait_test.go | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/pkg/e2e/wait_test.go b/pkg/e2e/wait_test.go index f607f5ea5..37e6903e0 100644 --- a/pkg/e2e/wait_test.go +++ b/pkg/e2e/wait_test.go @@ -21,6 +21,8 @@ import ( "testing" "time" + "gotest.tools/v3/icmd" + "gotest.tools/v3/assert" ) @@ -28,6 +30,12 @@ func TestWaitOnFaster(t *testing.T) { const projectName = "e2e-wait-faster" c := NewParallelCLI(t) + cleanup := func() { + c.RunDockerComposeCmd(t, "--project-name", projectName, "down", "--timeout=0", "--remove-orphans") + } + t.Cleanup(cleanup) + cleanup() + c.RunDockerComposeCmd(t, "-f", "./fixtures/wait/compose.yaml", "--project-name", projectName, "up", "-d") c.RunDockerComposeCmd(t, "--project-name", projectName, "wait", "faster") } @@ -36,6 +44,12 @@ func TestWaitOnSlower(t *testing.T) { const projectName = "e2e-wait-slower" c := NewParallelCLI(t) + cleanup := func() { + c.RunDockerComposeCmd(t, "--project-name", projectName, "down", "--timeout=0", "--remove-orphans") + } + t.Cleanup(cleanup) + cleanup() + c.RunDockerComposeCmd(t, "-f", "./fixtures/wait/compose.yaml", "--project-name", projectName, "up", "-d") c.RunDockerComposeCmd(t, "--project-name", projectName, "wait", "slower") } @@ -44,12 +58,27 @@ func TestWaitOnInfinity(t *testing.T) { const projectName = "e2e-wait-infinity" c := NewParallelCLI(t) + cleanup := func() { + c.RunDockerComposeCmd(t, "--project-name", projectName, "down", "--timeout=0", "--remove-orphans") + } + t.Cleanup(cleanup) + cleanup() + c.RunDockerComposeCmd(t, "-f", "./fixtures/wait/compose.yaml", "--project-name", projectName, "up", "-d") + cmd := c.NewDockerComposeCmd(t, "--project-name", projectName, "wait", "infinity") + r := icmd.StartCmd(cmd) + assert.NilError(t, r.Error) + t.Cleanup(func() { + if r.Cmd.Process != nil { + _ = r.Cmd.Process.Kill() + } + }) + finished := make(chan struct{}) ticker := time.NewTicker(7 * time.Second) go func() { - c.RunDockerComposeCmd(t, "--project-name", projectName, "wait", "infinity") + _ = r.Cmd.Wait() finished <- struct{}{} }() @@ -64,6 +93,12 @@ func TestWaitAndDrop(t *testing.T) { const projectName = "e2e-wait-and-drop" c := NewParallelCLI(t) + cleanup := func() { + c.RunDockerComposeCmd(t, "--project-name", projectName, "down", "--timeout=0", "--remove-orphans") + } + t.Cleanup(cleanup) + cleanup() + c.RunDockerComposeCmd(t, "-f", "./fixtures/wait/compose.yaml", "--project-name", projectName, "up", "-d") c.RunDockerComposeCmd(t, "--project-name", projectName, "wait", "--down-project", "faster")