From 4582a38a750f770578541ce0044df8f71c6d04ef Mon Sep 17 00:00:00 2001 From: Laura Brehm Date: Fri, 13 Dec 2024 17:16:59 +0000 Subject: [PATCH] run/tests: fix flaky RunAttachTermination test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit During an attached `docker run`, the CLI starts capturing signals so that they can be forwarded to the container. The CLI stops capturing signals after container is no longer running/it's streams are closed. This test was running into a race condition between signalling the running command with a SIGINT and closing the mock container's streams – If the signal syscall takes too long and the CLI realizes the streams are closed and stops the signal handling, the interrupt isn't captured and instead interrupts the test :') Fix this by only closing the stream after the ContainerKill call was made, which means the signal has already been captured. Signed-off-by: Laura Brehm --- cli/command/container/run_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cli/command/container/run_test.go b/cli/command/container/run_test.go index 81b176d904c9..5261b246d9d6 100644 --- a/cli/command/container/run_test.go +++ b/cli/command/container/run_test.go @@ -202,8 +202,6 @@ func TestRunAttachTermination(t *testing.T) { } assert.NilError(t, syscall.Kill(syscall.Getpid(), syscall.SIGINT)) - // end stream from "container" so that we'll detach - conn.Close() select { case <-killCh: @@ -211,6 +209,9 @@ func TestRunAttachTermination(t *testing.T) { t.Fatal("containerKillFunc was not called before the timeout") } + // end stream from "container" so that we'll detach + conn.Close() + select { case cmdErr := <-cmdErrC: assert.Equal(t, cmdErr, cli.StatusError{