@@ -278,21 +278,33 @@ func (s *DockerSuite) TestLogsFollowGoroutinesWithStdout(c *testing.T) {
278278 assert .NilError (c , err )
279279 cmd := exec .Command (dockerBinary , "logs" , "-f" , id )
280280 r , w := io .Pipe ()
281+ defer r .Close ()
282+ defer w .Close ()
283+
281284 cmd .Stdout = w
282285 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+ }()
284292
285293 // Make sure pipe is written to
286294 chErr := make (chan error )
287295 go func () {
288296 b := make ([]byte , 1 )
289297 _ , err := r .Read (b )
290298 chErr <- err
299+ r .Close ()
291300 }()
301+
302+ // Check read from pipe succeeded
292303 assert .NilError (c , <- chErr )
304+
293305 assert .NilError (c , cmd .Process .Kill ())
294- r . Close ()
295- cmd . Wait ()
306+ <- finished
307+
296308 // NGoroutines is not updated right away, so we need to wait before failing
297309 assert .NilError (c , waitForGoroutines (nroutines ))
298310}
@@ -306,10 +318,16 @@ func (s *DockerSuite) TestLogsFollowGoroutinesNoOutput(c *testing.T) {
306318 assert .NilError (c , err )
307319 cmd := exec .Command (dockerBinary , "logs" , "-f" , id )
308320 assert .NilError (c , cmd .Start ())
309- go cmd .Wait ()
321+
322+ finished := make (chan error )
323+ go func () {
324+ finished <- cmd .Wait ()
325+ }()
326+
310327 time .Sleep (200 * time .Millisecond )
311328 assert .NilError (c , cmd .Process .Kill ())
312- cmd .Wait ()
329+
330+ <- finished
313331
314332 // NGoroutines is not updated right away, so we need to wait before failing
315333 assert .NilError (c , waitForGoroutines (nroutines ))
0 commit comments