diff --git a/integration-cli/docker_cli_attach_unix_test.go b/integration-cli/docker_cli_attach_unix_test.go index ff519ea78d..64ac28bd72 100644 --- a/integration-cli/docker_cli_attach_unix_test.go +++ b/integration-cli/docker_cli_attach_unix_test.go @@ -13,34 +13,35 @@ import ( "github.com/kr/pty" ) -// #9860 +// #9860 Make sure attach ends when container ends (with no errors) func (s *DockerSuite) TestAttachClosedOnContainerStop(c *check.C) { - out, _ := dockerCmd(c, "run", "-dti", "busybox", "sleep", "2") + out, _ := dockerCmd(c, "run", "-dti", "busybox", "/bin/sh", "-c", `trap 'exit 0' SIGTERM; while true; do sleep 1; done`) id := strings.TrimSpace(out) c.Assert(waitRun(id), check.IsNil) + _, tty, err := pty.Open() + c.Assert(err, check.IsNil) + + attachCmd := exec.Command(dockerBinary, "attach", id) + attachCmd.Stdin = tty + attachCmd.Stdout = tty + attachCmd.Stderr = tty + err = attachCmd.Start() + c.Assert(err, check.IsNil) + errChan := make(chan error) go func() { defer close(errChan) - - _, tty, err := pty.Open() - if err != nil { - errChan <- err - return - } - attachCmd := exec.Command(dockerBinary, "attach", id) - attachCmd.Stdin = tty - attachCmd.Stdout = tty - attachCmd.Stderr = tty - - if err := attachCmd.Run(); err != nil { - errChan <- err - return - } + // Container is wating for us to signal it to stop + dockerCmd(c, "stop", id) + // And wait for the attach command to end + errChan <- attachCmd.Wait() }() + // Wait for the docker to end (should be done by the + // stop command in the go routine) dockerCmd(c, "wait", id) select {