Skip to content
This repository was archived by the owner on Oct 13, 2023. It is now read-only.

Commit 30a660e

Browse files
kolyshkinthaJeztah
authored andcommitted
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 <kolyshkin@gmail.com> (cherry picked from commit bc4ed69a23e1840b0ebae2b28531dd323cdba28f) Signed-off-by: Sebastiaan van Stijn <github@gone.nl> Upstream-commit: 149f69ca0604a8cdfbdef7e2f323d5c7dd208880 Component: cli
1 parent 1109168 commit 30a660e

1 file changed

Lines changed: 10 additions & 16 deletions

File tree

components/cli/e2e/container/proxy_signal_test.go

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,23 @@ import (
1717
// TestSigProxyWithTTY tests that killing the docker CLI forwards the signal to
1818
// the container, and kills the container's process. Test-case for moby/moby#28872
1919
func TestSigProxyWithTTY(t *testing.T) {
20-
_, tty, err := pty.Open()
21-
assert.NilError(t, err, "could not open pty")
22-
defer func() { _ = tty.Close() }()
20+
cmd := exec.Command("docker", "run", "-i", "-t", "--init", "--name", t.Name(), fixtures.BusyboxImage, "sleep", "30")
21+
p, err := pty.Start(cmd)
22+
defer func() {
23+
_ = cmd.Wait()
24+
_ = p.Close()
25+
}()
26+
assert.NilError(t, err, "failed to start container")
27+
defer icmd.RunCommand("docker", "container", "rm", "-f", t.Name())
2328

24-
containerName := "repro-28872"
25-
cmd := exec.Command("docker", "run", "-i", "-t", "--init", "--name", containerName, fixtures.BusyboxImage, "sleep", "30")
26-
cmd.Stdin = tty
27-
cmd.Stdout = tty
28-
cmd.Stderr = tty
29-
30-
err = cmd.Start()
31-
out, _ := cmd.CombinedOutput()
32-
assert.NilError(t, err, "failed to start container: %s", out)
33-
defer icmd.RunCommand("docker", "container", "rm", "-f", containerName)
34-
35-
poll.WaitOn(t, containerExistsWithStatus(t, containerName, "running"), poll.WithDelay(100*time.Millisecond), poll.WithTimeout(5*time.Second))
29+
poll.WaitOn(t, containerExistsWithStatus(t, t.Name(), "running"), poll.WithDelay(100*time.Millisecond), poll.WithTimeout(5*time.Second))
3630

3731
pid := cmd.Process.Pid
3832
t.Logf("terminating PID %d", pid)
3933
err = syscall.Kill(pid, syscall.SIGTERM)
4034
assert.NilError(t, err)
4135

42-
poll.WaitOn(t, containerExistsWithStatus(t, containerName, "exited"), poll.WithDelay(100*time.Millisecond), poll.WithTimeout(5*time.Second))
36+
poll.WaitOn(t, containerExistsWithStatus(t, t.Name(), "exited"), poll.WithDelay(100*time.Millisecond), poll.WithTimeout(5*time.Second))
4337
}
4438

4539
func containerExistsWithStatus(t *testing.T, containerID, status string) func(poll.LogT) poll.Result {

0 commit comments

Comments
 (0)