Fix TestAttachClosedOnContainerStop racey test
This test is failing once in a while on the CI, because the docker attach command might be called after the container ends. Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
parent
2ed0739c7a
commit
50852f3be3
1 changed files with 18 additions and 17 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue