@@ -278,21 +278,33 @@ func (s *DockerSuite) TestLogsFollowGoroutinesWithStdout(c *testing.T) {
278
278
assert .NilError (c , err )
279
279
cmd := exec .Command (dockerBinary , "logs" , "-f" , id )
280
280
r , w := io .Pipe ()
281
+ defer r .Close ()
282
+ defer w .Close ()
283
+
281
284
cmd .Stdout = w
282
285
assert .NilError (c , cmd .Start ())
283
- go cmd .Wait ()
286
+ defer cmd .Process .Kill ()
287
+
288
+ finished := make (chan error )
289
+ go func () {
290
+ finished <- cmd .Wait ()
291
+ }()
284
292
285
293
// Make sure pipe is written to
286
294
chErr := make (chan error )
287
295
go func () {
288
296
b := make ([]byte , 1 )
289
297
_ , err := r .Read (b )
290
298
chErr <- err
299
+ r .Close ()
291
300
}()
301
+
302
+ // Check read from pipe succeeded
292
303
assert .NilError (c , <- chErr )
304
+
293
305
assert .NilError (c , cmd .Process .Kill ())
294
- r . Close ()
295
- cmd . Wait ()
306
+ <- finished
307
+
296
308
// NGoroutines is not updated right away, so we need to wait before failing
297
309
assert .NilError (c , waitForGoroutines (nroutines ))
298
310
}
@@ -306,10 +318,16 @@ func (s *DockerSuite) TestLogsFollowGoroutinesNoOutput(c *testing.T) {
306
318
assert .NilError (c , err )
307
319
cmd := exec .Command (dockerBinary , "logs" , "-f" , id )
308
320
assert .NilError (c , cmd .Start ())
309
- go cmd .Wait ()
321
+
322
+ finished := make (chan error )
323
+ go func () {
324
+ finished <- cmd .Wait ()
325
+ }()
326
+
310
327
time .Sleep (200 * time .Millisecond )
311
328
assert .NilError (c , cmd .Process .Kill ())
312
- cmd .Wait ()
329
+
330
+ <- finished
313
331
314
332
// NGoroutines is not updated right away, so we need to wait before failing
315
333
assert .NilError (c , waitForGoroutines (nroutines ))
0 commit comments