Skip to content

Commit

Permalink
run/tests: fix flaky RunAttachTermination test
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
laurazard committed Dec 13, 2024
1 parent db4df1a commit 4582a38
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cli/command/container/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,16 @@ 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:
case <-time.After(5 * time.Second):
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{
Expand Down

0 comments on commit 4582a38

Please sign in to comment.