From 386e0f36c42593ef434517448ccfac5262f958d6 Mon Sep 17 00:00:00 2001 From: Dennis Chen Date: Thu, 24 May 2018 10:14:55 +0800 Subject: [PATCH] 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 --- integration-cli/docker_cli_exec_unix_test.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/integration-cli/docker_cli_exec_unix_test.go b/integration-cli/docker_cli_exec_unix_test.go index 337a90b116..4c77df4f11 100644 --- a/integration-cli/docker_cli_exec_unix_test.go +++ b/integration-cli/docker_cli_exec_unix_test.go @@ -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") } }