mirror of https://github.com/docker/cli.git
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>
This commit is contained in:
parent
68c2c10926
commit
bc4ed69a23
|
@ -17,29 +17,23 @@ import (
|
||||||
// TestSigProxyWithTTY tests that killing the docker CLI forwards the signal to
|
// 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
|
// the container, and kills the container's process. Test-case for moby/moby#28872
|
||||||
func TestSigProxyWithTTY(t *testing.T) {
|
func TestSigProxyWithTTY(t *testing.T) {
|
||||||
_, tty, err := pty.Open()
|
cmd := exec.Command("docker", "run", "-i", "-t", "--init", "--name", t.Name(), fixtures.BusyboxImage, "sleep", "30")
|
||||||
assert.NilError(t, err, "could not open pty")
|
p, err := pty.Start(cmd)
|
||||||
defer func() { _ = tty.Close() }()
|
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"
|
poll.WaitOn(t, containerExistsWithStatus(t, t.Name(), "running"), poll.WithDelay(100*time.Millisecond), poll.WithTimeout(5*time.Second))
|
||||||
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))
|
|
||||||
|
|
||||||
pid := cmd.Process.Pid
|
pid := cmd.Process.Pid
|
||||||
t.Logf("terminating PID %d", pid)
|
t.Logf("terminating PID %d", pid)
|
||||||
err = syscall.Kill(pid, syscall.SIGTERM)
|
err = syscall.Kill(pid, syscall.SIGTERM)
|
||||||
assert.NilError(t, err)
|
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 {
|
func containerExistsWithStatus(t *testing.T, containerID, status string) func(poll.LogT) poll.Result {
|
||||||
|
|
Loading…
Reference in New Issue