Skip to content

Commit 1a19197

Browse files
committed
run/tests: fix flaky RunAttachTermination test
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]>
1 parent a0cd512 commit 1a19197

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

cli/command/container/run_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,16 @@ func TestRunAttachTermination(t *testing.T) {
202202
}
203203

204204
assert.NilError(t, syscall.Kill(syscall.Getpid(), syscall.SIGINT))
205-
// end stream from "container" so that we'll detach
206-
conn.Close()
207205

208206
select {
209207
case <-killCh:
210208
case <-time.After(5 * time.Second):
211209
t.Fatal("containerKillFunc was not called before the timeout")
212210
}
213211

212+
// end stream from "container" so that we'll detach
213+
conn.Close()
214+
214215
select {
215216
case cmdErr := <-cmdErrC:
216217
assert.Equal(t, cmdErr, cli.StatusError{

0 commit comments

Comments
 (0)