From 683ba62f3e904e5ab7c60c40a265e9d0fe84fd60 Mon Sep 17 00:00:00 2001 From: Paul Scott <408401+icio@users.noreply.github.com> Date: Mon, 11 Sep 2023 19:06:11 +0100 Subject: [PATCH] cmd/testwrapper: fix exit deflake (#9342) Sometimes `go test` would exit and close its stdout before we started reading it, and we would return that "file closed" error then forget to os.Exit(1). Fixed to prefer the go test subprocess error and exit regardless of the type of error. Fixes #9334 Signed-off-by: Paul Scott --- cmd/testwrapper/testwrapper.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cmd/testwrapper/testwrapper.go b/cmd/testwrapper/testwrapper.go index 9f5d13bbd..92cad5072 100644 --- a/cmd/testwrapper/testwrapper.go +++ b/cmd/testwrapper/testwrapper.go @@ -89,11 +89,6 @@ func runTests(ctx context.Context, attempt int, pt *packageTests, otherArgs []st log.Printf("error starting test: %v", err) os.Exit(1) } - cmdErr := make(chan error, 1) - go func() { - defer close(cmdErr) - cmdErr <- cmd.Wait() - }() s := bufio.NewScanner(r) resultMap := make(map[string]map[string]*testAttempt) // pkg -> test -> testAttempt @@ -164,10 +159,13 @@ func runTests(ctx context.Context, attempt int, pt *packageTests, otherArgs []st } } } - if err := s.Err(); err != nil { + if err := cmd.Wait(); err != nil { return err } - return <-cmdErr + if err := s.Err(); err != nil { + return fmt.Errorf("reading go test stdout: %w", err) + } + return nil } func main() { @@ -303,6 +301,8 @@ func main() { os.Exit(exit.ExitCode()) } } + log.Printf("testwrapper: %s", err) + os.Exit(1) } } if len(toRetry) == 0 {