Skip to content

Commit 864cc1c

Browse files
authored
Merge pull request #44765 from vvoland/fix-test-race-logs-goroutines-20
[20.10 backport] integration-cli: Fix hanging TestLogsFollowGoroutines*
2 parents 8771b4b + 91e767c commit 864cc1c

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

integration-cli/docker_cli_logs_test.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)