Skip to content

Commit

Permalink
Merge pull request #44765 from vvoland/fix-test-race-logs-goroutines-20
Browse files Browse the repository at this point in the history
[20.10 backport] integration-cli: Fix hanging TestLogsFollowGoroutines*
  • Loading branch information
thaJeztah authored Jan 10, 2023
2 parents 8771b4b + 91e767c commit 864cc1c
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions integration-cli/docker_cli_logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,21 +278,33 @@ func (s *DockerSuite) TestLogsFollowGoroutinesWithStdout(c *testing.T) {
assert.NilError(c, err)
cmd := exec.Command(dockerBinary, "logs", "-f", id)
r, w := io.Pipe()
defer r.Close()
defer w.Close()

cmd.Stdout = w
assert.NilError(c, cmd.Start())
go cmd.Wait()
defer cmd.Process.Kill()

finished := make(chan error)
go func() {
finished <- cmd.Wait()
}()

// Make sure pipe is written to
chErr := make(chan error)
go func() {
b := make([]byte, 1)
_, err := r.Read(b)
chErr <- err
r.Close()
}()

// Check read from pipe succeeded
assert.NilError(c, <-chErr)

assert.NilError(c, cmd.Process.Kill())
r.Close()
cmd.Wait()
<-finished

// NGoroutines is not updated right away, so we need to wait before failing
assert.NilError(c, waitForGoroutines(nroutines))
}
Expand All @@ -306,10 +318,16 @@ func (s *DockerSuite) TestLogsFollowGoroutinesNoOutput(c *testing.T) {
assert.NilError(c, err)
cmd := exec.Command(dockerBinary, "logs", "-f", id)
assert.NilError(c, cmd.Start())
go cmd.Wait()

finished := make(chan error)
go func() {
finished <- cmd.Wait()
}()

time.Sleep(200 * time.Millisecond)
assert.NilError(c, cmd.Process.Kill())
cmd.Wait()

<-finished

// NGoroutines is not updated right away, so we need to wait before failing
assert.NilError(c, waitForGoroutines(nroutines))
Expand Down

0 comments on commit 864cc1c

Please sign in to comment.