Skip to content

Commit

Permalink
pam/integration-tests/vhs: Write the race log in a separate file
Browse files Browse the repository at this point in the history
We were relying on the process output to check on data races, while Go allows
us to write the race content
  • Loading branch information
3v1n0 committed Jan 20, 2025
1 parent 375a15d commit 6c1bf10
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
35 changes: 25 additions & 10 deletions pam/integration-tests/vhs-helpers_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main_test

import (
"errors"
"fmt"
"maps"
"math"
Expand Down Expand Up @@ -245,10 +246,17 @@ func (td tapeData) RunVhs(t *testing.T, testType vhsTestType, outDir string, cli
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", pam_test.RunnerEnvLogFile, e))
}

var raceLog string
if testutils.IsRace() {
raceLog = filepath.Join(t.TempDir(), "gorace.log")
cmd.Env = append(cmd.Env, fmt.Sprintf("GORACE=log_path=%s", raceLog))
saveArtifactsForDebugOnCleanup(t, []string{raceLog})
}

cmd.Args = append(cmd.Args, td.PrepareTape(t, testType, outDir))
out, err := cmd.CombinedOutput()
if err != nil {
maybeIgnoreKnownDataRace(t, string(out))
checkDataRace(t, raceLog)
}

isSSHError := func(processOut []byte) bool {
Expand Down Expand Up @@ -305,13 +313,21 @@ func (td tapeData) Output() string {
return txt
}

func maybeIgnoreKnownDataRace(t *testing.T, out string) {
func checkDataRace(t *testing.T, raceLog string) {
t.Helper()

if !testutils.IsRace() {
if !testutils.IsRace() || raceLog == "" {
return
}

content, err := os.ReadFile(raceLog)
if err == nil || errors.Is(err, os.ErrNotExist) {
return
}
if !strings.Contains(out, "WARNING: DATA RACE") {
require.NoError(t, err, "TearDown: Error reading race log %q", raceLog)

out := string(content)
if strings.TrimSpace(out) == "" {
return
}

Expand All @@ -320,14 +336,13 @@ func maybeIgnoreKnownDataRace(t *testing.T, out string) {
// https://github.com/charmbracelet/bubbletea/issues/909
// We can't do much here, as the workaround will likely affect the
// GUI behavior, but we ignore this since it's definitely not our bug.
defer t.Skip("This is a very well known bubble tea bug (#909), ignoring it")
if testutils.IsVerbose() {
t.Logf("Ignored bubbletea race:\n%s", out)
return
}

fmt.Fprintf(os.Stderr, "Ignored bubbletea race:\n%s", out)
// TODO: In case other races are detected, we should still fail here.
t.Skipf("This is a very well known bubble tea bug (#909), ignoring it:\n%s", out)
return
}

t.Fatalf("Got a GO Race on vhs child:\n%s", out)
}

func (td tapeData) ExpectedOutput(t *testing.T, outputDir string) string {
Expand Down
3 changes: 3 additions & 0 deletions pam/tools/pam-runner/pam-runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ func main() {
if coverDir := os.Getenv("GOCOVERDIR"); coverDir != "" {
defaultArgs = append(defaultArgs, "--exec-env", fmt.Sprintf("GOCOVERDIR=%s", coverDir))
}
if goRace := os.Getenv("GORACE"); goRace != "" {
defaultArgs = append(defaultArgs, "--exec-env", fmt.Sprintf("GORACE=%s", goRace))
}
if asanOptions := os.Getenv("ASAN_OPTIONS"); asanOptions != "" {
defaultArgs = append(defaultArgs, "--exec-env", fmt.Sprintf("ASAN_OPTIONS=%s", asanOptions))
}
Expand Down

0 comments on commit 6c1bf10

Please sign in to comment.