Skip to content

Commit ec5b10a

Browse files
authored
Fixes flakeguard bug that silently absorbs build errors (#1739)
1 parent 4ecc564 commit ec5b10a

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

tools/flakeguard/runner/runner.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"errors"
77
"fmt"
8+
"io"
89
"os"
910
"os/exec"
1011
"path/filepath"
@@ -25,8 +26,10 @@ const (
2526
)
2627

2728
var (
28-
startPanicRe = regexp.MustCompile(`^panic:`)
29-
startRaceRe = regexp.MustCompile(`^WARNING: DATA RACE`)
29+
startPanicRe = regexp.MustCompile(`^panic:`)
30+
startRaceRe = regexp.MustCompile(`^WARNING: DATA RACE`)
31+
buildErr = errors.New("failed to build test code")
32+
failedToShowBuildErr = errors.New("flakeguard failed to show build errors")
3033
)
3134

3235
// Runner describes the test run parameters and raw test outputs
@@ -297,6 +300,19 @@ func (r *Runner) parseTestResults(runPrefix string, runCount int) ([]reports.Tes
297300
context := append(precedingLines, followingLines...)
298301
return nil, fmt.Errorf("failed to parse json test output near lines:\n%s\nerror: %w", strings.Join(context, "\n"), err)
299302
}
303+
if entryLine.Action == "build-fail" {
304+
_, err := file.Seek(0, 0)
305+
if err != nil {
306+
return nil, fmt.Errorf("%w: %w", failedToShowBuildErr, buildErr)
307+
}
308+
// Print all build errors
309+
buildErrs, err := io.ReadAll(file)
310+
if err != nil {
311+
return nil, fmt.Errorf("%w: %w", failedToShowBuildErr, buildErr)
312+
}
313+
fmt.Println(string(buildErrs))
314+
return nil, buildErr
315+
}
300316

301317
var result *reports.TestResult
302318
if entryLine.Test != "" {

tools/flakeguard/runner/runner_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,24 @@ type expectedTestResult struct {
4141
seen bool
4242
}
4343

44+
func TestNoCompileTests(t *testing.T) {
45+
// Test that we are not swallowing test compilation errors
46+
t.Parallel()
47+
48+
runner := Runner{
49+
ProjectPath: "./",
50+
Verbose: true,
51+
RunCount: 1,
52+
GoTestRaceFlag: false,
53+
FailFast: false,
54+
}
55+
56+
_, err := runner.RunTestPackages([]string{"./example_bad_test_package"})
57+
require.Error(t, err)
58+
require.ErrorIs(t, err, buildErr, "expected a compile error")
59+
require.NotErrorIs(t, err, failedToShowBuildErr, "should be able to print out build errors")
60+
}
61+
4462
func TestPrettyProjectPath(t *testing.T) {
4563
t.Parallel()
4664

0 commit comments

Comments
 (0)