Browse code

Merge pull request #29773 from forever043/fix_TestDaemonStartWithoutColors

test: Fix "--raw-logs=true" option test in TestDaemonStartWithoutColors

Vincent Demeester authored on 2017/01/03 17:29:19
Showing 1 changed files
... ...
@@ -2165,6 +2165,9 @@ func (s *DockerDaemonSuite) TestDaemonStartWithoutColors(c *check.C) {
2165 2165
 
2166 2166
 	infoLog := "\x1b[34mINFO\x1b"
2167 2167
 
2168
+	b := bytes.NewBuffer(nil)
2169
+	done := make(chan bool)
2170
+
2168 2171
 	p, tty, err := pty.Open()
2169 2172
 	c.Assert(err, checker.IsNil)
2170 2173
 	defer func() {
... ...
@@ -2172,19 +2175,38 @@ func (s *DockerDaemonSuite) TestDaemonStartWithoutColors(c *check.C) {
2172 2172
 		p.Close()
2173 2173
 	}()
2174 2174
 
2175
-	b := bytes.NewBuffer(nil)
2176
-	go io.Copy(b, p)
2175
+	go func() {
2176
+		io.Copy(b, p)
2177
+		done <- true
2178
+	}()
2177 2179
 
2178 2180
 	// Enable coloring explicitly
2179 2181
 	s.d.StartWithLogFile(tty, "--raw-logs=false")
2180 2182
 	s.d.Stop(c)
2183
+	// Wait for io.Copy() before checking output
2184
+	<-done
2181 2185
 	c.Assert(b.String(), checker.Contains, infoLog)
2182 2186
 
2183 2187
 	b.Reset()
2184 2188
 
2189
+	// "tty" is already closed in prev s.d.Stop(),
2190
+	// we have to close the other side "p" and open another pair of
2191
+	// pty for the next test.
2192
+	p.Close()
2193
+	p, tty, err = pty.Open()
2194
+	c.Assert(err, checker.IsNil)
2195
+
2196
+	go func() {
2197
+		io.Copy(b, p)
2198
+		done <- true
2199
+	}()
2200
+
2185 2201
 	// Disable coloring explicitly
2186 2202
 	s.d.StartWithLogFile(tty, "--raw-logs=true")
2187 2203
 	s.d.Stop(c)
2204
+	// Wait for io.Copy() before checking output
2205
+	<-done
2206
+	c.Assert(b.String(), check.Not(check.Equals), "")
2188 2207
 	c.Assert(b.String(), check.Not(checker.Contains), infoLog)
2189 2208
 }
2190 2209