Skip to content

Commit

Permalink
e2e-upgrade: guard function return values behind sync.WaitGroup (#3461
Browse files Browse the repository at this point in the history
)

Signed-off-by: Daniel Weiße <[email protected]>
  • Loading branch information
daniel-weisse authored Oct 28, 2024
1 parent 132218a commit 4b7cd84
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions e2e/internal/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ func runCommandWithSeparateOutputs(cmd *exec.Cmd) (stdout, stderr []byte, err er
return
}

continuouslyPrintOutput := func(r io.Reader, prefix string) {
continuouslyPrintOutput := func(r io.Reader, prefix string, wg *sync.WaitGroup) {
defer wg.Done()
scanner := bufio.NewScanner(r)
for scanner.Scan() {
output := scanner.Text()
Expand All @@ -196,12 +197,15 @@ func runCommandWithSeparateOutputs(cmd *exec.Cmd) (stdout, stderr []byte, err er
}
}

go continuouslyPrintOutput(stdoutIn, "stdout")
go continuouslyPrintOutput(stderrIn, "stderr")
wg := &sync.WaitGroup{}
wg.Add(2)
go continuouslyPrintOutput(stdoutIn, "stdout", wg)
go continuouslyPrintOutput(stderrIn, "stderr", wg)

if err = cmd.Wait(); err != nil {
err = fmt.Errorf("wait for command to finish: %w", err)
}
wg.Wait()

return stdout, stderr, err
}
Expand Down

0 comments on commit 4b7cd84

Please sign in to comment.