Skip to content

Commit

Permalink
Merge pull request #107 from knabben/knabben/fix-buffer-read
Browse files Browse the repository at this point in the history
Parallel reading of pipes and strerr read
  • Loading branch information
knabben authored Jan 23, 2024
2 parents bea2de9 + 5d953af commit cab2534
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions pkg/testcases/cases.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"bufio"
"io"
"os/exec"
"sync"

"go.uber.org/zap"
)
Expand Down Expand Up @@ -68,9 +69,13 @@ func (t *TestCase) RunTest(testCtx *TestContext, prefix string) error {
return err
}

redirectOutput(stdout)
redirectOutput(stderr)
var wg sync.WaitGroup
wg.Add(1)

go redirectOutput(&wg, stdout)
redirectOutput(nil, stderr)

wg.Wait()
return cmd.Wait()
}

Expand Down Expand Up @@ -119,11 +124,17 @@ func buildCmd(t *TestCase, testCtx *TestContext, prefix string) *exec.Cmd {
return exec.Command(testCtx.E2EBinary, args...)
}

func redirectOutput(stdout io.ReadCloser) {
func redirectOutput(wg *sync.WaitGroup, stdout io.ReadCloser) {
if wg != nil {
defer wg.Done()
}
scanner := bufio.NewScanner(stdout)
scanner.Split(bufio.ScanLines)
for scanner.Scan() {
m := scanner.Text()
zap.L().Info(m)
}
if err := scanner.Err(); err != nil {
zap.L().Error(err.Error())
}
}

0 comments on commit cab2534

Please sign in to comment.