summaryrefslogtreecommitdiff
path: root/integration-cli
diff options
context:
space:
mode:
authorPaweł Gronowski <pawel.gronowski@docker.com>2023-01-05 13:01:27 +0100
committerPaweł Gronowski <pawel.gronowski@docker.com>2023-01-05 18:10:32 +0100
commitdeb4910c5b2aa231a5b0f1b96c6a1812222df492 (patch)
tree4d15cf0bc50afe1d513f51c3e50a180f734428ed /integration-cli
parentfcb52454acdfd3de635aa2c17f72ca4ee7d526d1 (diff)
downloaddocker-deb4910c5b2aa231a5b0f1b96c6a1812222df492.tar.gz
integration-cli: Fix hanging TestLogsFollowGoroutines*
cmd.Wait is called twice from different goroutines which can cause the test to hang completely. Fix by calling Wait only once and sending its return value over a channel. In TestLogsFollowGoroutinesWithStdout also added additional closes and process kills to ensure that we don't leak anything in case test returns early because of failed test assertion. Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
Diffstat (limited to 'integration-cli')
-rw-r--r--integration-cli/docker_cli_logs_test.go28
1 files changed, 23 insertions, 5 deletions
diff --git a/integration-cli/docker_cli_logs_test.go b/integration-cli/docker_cli_logs_test.go
index e46deb91f7..cca5c9438e 100644
--- a/integration-cli/docker_cli_logs_test.go
+++ b/integration-cli/docker_cli_logs_test.go
@@ -290,9 +290,17 @@ func (s *DockerCLILogsSuite) 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)
@@ -300,11 +308,15 @@ func (s *DockerCLILogsSuite) TestLogsFollowGoroutinesWithStdout(c *testing.T) {
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))
}
@@ -318,10 +330,16 @@ func (s *DockerCLILogsSuite) 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))