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>
pull/9353/head
Paul Scott 9 months ago committed by GitHub
parent 0396366aae
commit 683ba62f3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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

Loading…
Cancel
Save