From bc4ed69a23e1840b0ebae2b28531dd323cdba28f Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Tue, 23 Jul 2019 17:12:16 -0700 Subject: [PATCH] TestSigProxyWithTTY: fix exec.CombinedOutput should not be used here because: - it redirects cmd Stdout and Stderr and we want it to be the tty - it calls cmd.Run which we already did While at it - use pty.Start() as it is cleaner - make sure we don't leave a zombie running, by calling Wait() in defer - use test.Name() for containerName Signed-off-by: Kir Kolyshkin --- e2e/container/proxy_signal_test.go | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/e2e/container/proxy_signal_test.go b/e2e/container/proxy_signal_test.go index c65da0cfc1..c6d801199f 100644 --- a/e2e/container/proxy_signal_test.go +++ b/e2e/container/proxy_signal_test.go @@ -17,29 +17,23 @@ import ( // TestSigProxyWithTTY tests that killing the docker CLI forwards the signal to // the container, and kills the container's process. Test-case for moby/moby#28872 func TestSigProxyWithTTY(t *testing.T) { - _, tty, err := pty.Open() - assert.NilError(t, err, "could not open pty") - defer func() { _ = tty.Close() }() + cmd := exec.Command("docker", "run", "-i", "-t", "--init", "--name", t.Name(), fixtures.BusyboxImage, "sleep", "30") + p, err := pty.Start(cmd) + defer func() { + _ = cmd.Wait() + _ = p.Close() + }() + assert.NilError(t, err, "failed to start container") + defer icmd.RunCommand("docker", "container", "rm", "-f", t.Name()) - containerName := "repro-28872" - cmd := exec.Command("docker", "run", "-i", "-t", "--init", "--name", containerName, fixtures.BusyboxImage, "sleep", "30") - cmd.Stdin = tty - cmd.Stdout = tty - cmd.Stderr = tty - - err = cmd.Start() - out, _ := cmd.CombinedOutput() - assert.NilError(t, err, "failed to start container: %s", out) - defer icmd.RunCommand("docker", "container", "rm", "-f", containerName) - - poll.WaitOn(t, containerExistsWithStatus(t, containerName, "running"), poll.WithDelay(100*time.Millisecond), poll.WithTimeout(5*time.Second)) + poll.WaitOn(t, containerExistsWithStatus(t, t.Name(), "running"), poll.WithDelay(100*time.Millisecond), poll.WithTimeout(5*time.Second)) pid := cmd.Process.Pid t.Logf("terminating PID %d", pid) err = syscall.Kill(pid, syscall.SIGTERM) assert.NilError(t, err) - poll.WaitOn(t, containerExistsWithStatus(t, containerName, "exited"), poll.WithDelay(100*time.Millisecond), poll.WithTimeout(5*time.Second)) + poll.WaitOn(t, containerExistsWithStatus(t, t.Name(), "exited"), poll.WithDelay(100*time.Millisecond), poll.WithTimeout(5*time.Second)) } func containerExistsWithStatus(t *testing.T, containerID, status string) func(poll.LogT) poll.Result {