Skip to content

Commit 99efc45

Browse files
committed
Mostly fixes panics
1 parent 250e597 commit 99efc45

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

tools/flakeguard/runner/runner.go

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,14 @@ func (r *Runner) RunTests() ([]reports.TestResult, error) {
6767
if err != nil {
6868
return nil, fmt.Errorf("failed to parse test results: %w", err)
6969
}
70-
for _, report := range reports {
71-
if report.Panics >= report.Runs { // This feels hacky, but there aren't any elegant solutions
72-
report.Failures = 0 // We can sometimes double-count panics as failures
73-
report.Panics = report.Runs
70+
for index, report := range reports {
71+
if report.Panics >= r.RunCount { // This feels hacky, but there aren't any elegant solutions
72+
reports[index].Failures = 0 // We can sometimes double-count panics as failures
73+
reports[index].Panics = r.RunCount
74+
reports[index].Runs = r.RunCount
7475
}
7576
}
76-
return parseTestResults(jsonFilePaths)
77+
return reports, nil
7778
}
7879

7980
// RawOutput retrieves the raw output from the test runs, if CollectRawOutput enabled.
@@ -242,11 +243,12 @@ func parseTestResults(filePaths []string) ([]reports.TestResult, error) {
242243
testDetails[panicTestKey].Panicked = true
243244
testDetails[panicTestKey].Panics++
244245
testDetails[panicTestKey].Runs++
245-
duration, err := time.ParseDuration(strconv.FormatFloat(entryLine.Elapsed, 'f', -1, 64) + "s")
246-
if err != nil {
247-
return nil, fmt.Errorf("failed to parse duration: %w", err)
248-
}
249-
testDetails[panicTestKey].Durations = append(testDetails[panicTestKey].Durations, duration)
246+
// TODO: durations and panics are weird in the same way as Runs: lots of double-counting
247+
// duration, err := time.ParseDuration(strconv.FormatFloat(entryLine.Elapsed, 'f', -1, 64) + "s")
248+
// if err != nil {
249+
// return nil, fmt.Errorf("failed to parse duration: %w", err)
250+
// }
251+
// testDetails[raceTestKey].Durations = append(testDetails[raceTestKey].Durations, duration)
250252
testDetails[panicTestKey].Outputs = append(testDetails[panicTestKey].Outputs, entryLine.Output)
251253
for _, entry := range detectedEntries {
252254
if entry.Test == "" {
@@ -263,11 +265,12 @@ func parseTestResults(filePaths []string) ([]reports.TestResult, error) {
263265
raceTestKey := fmt.Sprintf("%s/%s", entryLine.Package, raceTest)
264266
testDetails[raceTestKey].Races++
265267
testDetails[raceTestKey].Runs++
266-
duration, err := time.ParseDuration(strconv.FormatFloat(entryLine.Elapsed, 'f', -1, 64) + "s")
267-
if err != nil {
268-
return nil, fmt.Errorf("failed to parse duration: %w", err)
269-
}
270-
testDetails[raceTestKey].Durations = append(testDetails[raceTestKey].Durations, duration)
268+
// TODO: durations and races are weird in the same way as Runs: lots of double-counting
269+
// duration, err := time.ParseDuration(strconv.FormatFloat(entryLine.Elapsed, 'f', -1, 64) + "s")
270+
// if err != nil {
271+
// return nil, fmt.Errorf("failed to parse duration: %w", err)
272+
// }
273+
// testDetails[raceTestKey].Durations = append(testDetails[raceTestKey].Durations, duration)
271274
testDetails[raceTestKey].Outputs = append(testDetails[raceTestKey].Outputs, entryLine.Output)
272275
for _, entry := range detectedEntries {
273276
if entry.Test == "" {

tools/flakeguard/runner/runner_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,9 @@ func TestRun(t *testing.T) {
260260
require.False(t, expected.seen, "test '%s' was seen multiple times", result.TestName)
261261
expected.seen = true
262262

263-
assert.Len(t, result.Durations, result.Runs, "test '%s' has a mismatch of runs and duration counts", result.TestName, defaultRuns)
263+
assert.Len(t, result.Durations, result.Runs, "test '%s' has a mismatch of runs and duration counts\nIf this is a panic test, this is expected (but strange and buggy) behavior",
264+
result.TestName, defaultRuns,
265+
)
264266
resultCounts := result.Successes + result.Failures + result.Panics + result.Skips
265267
assert.Equal(t, result.Runs, resultCounts,
266268
"test '%s' doesn't match Runs count with results counts\n%s", result.TestName, resultsString(result),

0 commit comments

Comments
 (0)