Skip to content

Commit

Permalink
Alternative failure mitigation of TestExecInteractiveStdinClose
Browse files Browse the repository at this point in the history
Begin to copy the data until the command to exit and any coping to
stdin or copy from stdout/stderr has completed.
Also adding defense code to trim the possible '\x00' null value.

Signed-off-by: Dennis Chen <[email protected]>
  • Loading branch information
arm64b committed May 28, 2018
1 parent 9c2c887 commit 386e0f3
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions integration-cli/docker_cli_exec_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,21 @@ func (s *DockerSuite) TestExecInteractiveStdinClose(c *check.C) {
c.Assert(err, checker.IsNil)

b := bytes.NewBuffer(nil)
go func() {
io.Copy(b, p)
p.Close()
}()

ch := make(chan error)
go func() { ch <- cmd.Wait() }()

select {
case err := <-ch:
c.Assert(err, checker.IsNil)
output := b.String()
io.Copy(b, p)
p.Close()
bs := b.Bytes()
bs = bytes.Trim(bs, "\x00")
output := string(bs[:])
c.Assert(strings.TrimSpace(output), checker.Equals, "hello")
case <-time.After(5 * time.Second):
p.Close()
c.Fatal("timed out running docker exec")
}
}
Expand Down

0 comments on commit 386e0f3

Please sign in to comment.