From 31c2689d03d33975fa126e4796fc30fbf301aa74 Mon Sep 17 00:00:00 2001 From: majiuyue 00385406 Date: Thu, 29 Dec 2016 16:34:11 +0800 Subject: [PATCH] test: Fix "--raw-logs=true" option test in TestDaemonStartWithoutColors Because "tty" is closed in s.d.Stop() for "--raw-logs=false" test, we need to open another pair of pty before test "--raw-logs=true" option. This patch fix #29772. Signed-off-by: Jiuyue Ma Upstream-commit: c9e0d923ae6d2b5558378183b79d0a85ccf16020 Component: engine --- .../integration-cli/docker_cli_daemon_test.go | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/components/engine/integration-cli/docker_cli_daemon_test.go b/components/engine/integration-cli/docker_cli_daemon_test.go index b6a3dd22b1..c716bdf73d 100644 --- a/components/engine/integration-cli/docker_cli_daemon_test.go +++ b/components/engine/integration-cli/docker_cli_daemon_test.go @@ -2165,6 +2165,9 @@ func (s *DockerDaemonSuite) TestDaemonStartWithoutColors(c *check.C) { infoLog := "\x1b[34mINFO\x1b" + b := bytes.NewBuffer(nil) + done := make(chan bool) + p, tty, err := pty.Open() c.Assert(err, checker.IsNil) defer func() { @@ -2172,19 +2175,38 @@ func (s *DockerDaemonSuite) TestDaemonStartWithoutColors(c *check.C) { p.Close() }() - b := bytes.NewBuffer(nil) - go io.Copy(b, p) + go func() { + io.Copy(b, p) + done <- true + }() // Enable coloring explicitly s.d.StartWithLogFile(tty, "--raw-logs=false") s.d.Stop(c) + // Wait for io.Copy() before checking output + <-done c.Assert(b.String(), checker.Contains, infoLog) b.Reset() + // "tty" is already closed in prev s.d.Stop(), + // we have to close the other side "p" and open another pair of + // pty for the next test. + p.Close() + p, tty, err = pty.Open() + c.Assert(err, checker.IsNil) + + go func() { + io.Copy(b, p) + done <- true + }() + // Disable coloring explicitly s.d.StartWithLogFile(tty, "--raw-logs=true") s.d.Stop(c) + // Wait for io.Copy() before checking output + <-done + c.Assert(b.String(), check.Not(check.Equals), "") c.Assert(b.String(), check.Not(checker.Contains), infoLog) }