Alternative failure mitigation of `TestExecInteractiveStdinClose`

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 <dennis.chen@arm.com>
This commit is contained in:
Dennis Chen 2018-05-24 10:14:55 +08:00
parent 9c2c887b12
commit 386e0f36c4
1 changed files with 6 additions and 5 deletions

View File

@ -25,10 +25,6 @@ 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() }()
@ -36,9 +32,14 @@ func (s *DockerSuite) TestExecInteractiveStdinClose(c *check.C) {
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")
}
}