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 <paul@tailscale.com>
This commit is contained in:
Paul Scott 2023-09-11 19:06:11 +01:00 committed by GitHub
parent 0396366aae
commit 683ba62f3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 {