summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Haller <stefan@haller-berlin.de>2023-09-09 13:41:26 +0200
committerStefan Haller <stefan@haller-berlin.de>2023-09-25 09:09:41 +0200
commit59cc6843e6e9b969759291571cab876b0a5cdac4 (patch)
tree06045b1fd7d6d79629e2a1f7bd1501e592ea87c0
parentf108fd2236ad7d61f0c4ee824b265653ef1d8dad (diff)
Print race detector logs after running a test with -race
-rw-r--r--pkg/integration/clients/cli.go7
-rw-r--r--pkg/integration/clients/go_test.go8
-rw-r--r--pkg/integration/components/runner.go20
3 files changed, 22 insertions, 13 deletions
diff --git a/pkg/integration/clients/cli.go b/pkg/integration/clients/cli.go
index 974f3493c..d6cf5a628 100644
--- a/pkg/integration/clients/cli.go
+++ b/pkg/integration/clients/cli.go
@@ -88,12 +88,15 @@ outer:
return testsToRun
}
-func runCmdInTerminal(cmd *exec.Cmd) error {
+func runCmdInTerminal(cmd *exec.Cmd) (int, error) {
cmd.Stdout = os.Stdout
cmd.Stdin = os.Stdin
cmd.Stderr = os.Stderr
- return cmd.Run()
+ if err := cmd.Start(); err != nil {
+ return -1, err
+ }
+ return cmd.Process.Pid, cmd.Wait()
}
func tryConvert(numStr string, defaultVal int) int {
diff --git a/pkg/integration/clients/go_test.go b/pkg/integration/clients/go_test.go
index ccaae2bd9..6503621ba 100644
--- a/pkg/integration/clients/go_test.go
+++ b/pkg/integration/clients/go_test.go
@@ -63,7 +63,7 @@ func TestIntegration(t *testing.T) {
assert.NoError(t, err)
}
-func runCmdHeadless(cmd *exec.Cmd) error {
+func runCmdHeadless(cmd *exec.Cmd) (int, error) {
cmd.Env = append(
cmd.Env,
"HEADLESS=true",
@@ -81,7 +81,7 @@ func runCmdHeadless(cmd *exec.Cmd) error {
// running other commands in a pty.
f, err := pty.StartWithSize(cmd, &pty.Winsize{Rows: 300, Cols: 300})
if err != nil {
- return err
+ return -1, err
}
_, _ = io.Copy(io.Discard, f)
@@ -89,8 +89,8 @@ func runCmdHeadless(cmd *exec.Cmd) error {
if cmd.Wait() != nil {
_ = f.Close()
// return an error with the stderr output
- return errors.New(stderr.String())
+ return cmd.Process.Pid, errors.New(stderr.String())
}
- return f.Close()
+ return cmd.Process.Pid, f.Close()
}
diff --git a/pkg/integration/components/runner.go b/pkg/integration/components/runner.go
index 569be8d28..821319dc1 100644
--- a/pkg/integration/components/runner.go
+++ b/pkg/integration/components/runner.go
@@ -26,7 +26,7 @@ const (
func RunTests(
tests []*IntegrationTest,
logf func(format string, formatArgs ...interface{}),
- runCmd func(cmd *exec.Cmd) error,
+ runCmd func(cmd *exec.Cmd) (int, error),
testWrapper func(test *IntegrationTest, f func() error),
sandbox bool,
waitForDebugger bool,
@@ -60,7 +60,7 @@ func RunTests(
)
for i := 0; i < maxAttempts; i++ {
- err := runTest(test, paths, projectRootDir, logf, runCmd, sandbox, waitForDebugger, inputDelay, gitVersion)
+ err := runTest(test, paths, projectRootDir, logf, runCmd, sandbox, waitForDebugger, raceDetector, inputDelay, gitVersion)
if err != nil {
if i == maxAttempts-1 {
return err
@@ -83,9 +83,10 @@ func runTest(
paths Paths,
projectRootDir string,
logf func(format string, formatArgs ...interface{}),
- runCmd func(cmd *exec.Cmd) error,
+ runCmd func(cmd *exec.Cmd) (int, error),
sandbox bool,
waitForDebugger bool,
+ raceDetector bool,
inputDelay int,
gitVersion *git_commands.GitVersion,
) error {
@@ -108,12 +109,17 @@ func runTest(
return err
}
- err = runCmd(cmd)
- if err != nil {
- return err
+ pid, err := runCmd(cmd)
+
+ // Print race detector log regardless of the command's exit status
+ if raceDetector {
+ logPath := fmt.Sprintf("%s.%d", raceDetectorLogsPath(), pid)
+ if bytes, err := os.ReadFile(logPath); err == nil {
+ logf("Race detector log:\n" + string(bytes))
+ }
}
- return nil
+ return err
}
func prepareTestDir(