Skip to content

Commit edfd2a4

Browse files
committed
Add OmitOutputsOnSuccess
1 parent 361bf93 commit edfd2a4

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

tools/flakeguard/runner/runner.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,14 @@ func (r *Runner) parseTestResults(filePaths []string) ([]reports.TestResult, err
481481
results = append(results, *result)
482482
}
483483

484+
// Omit success outputs if requested
485+
if r.OmitOutputsOnSuccess {
486+
for i := range results {
487+
results[i].PassedOutputs = make(map[string][]string)
488+
results[i].Outputs = make(map[string][]string)
489+
}
490+
}
491+
484492
return results, nil
485493
}
486494

tools/flakeguard/runner/runner_test.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,74 @@ func TestAttributeRaceToTest(t *testing.T) {
496496
}
497497
}
498498

499+
func TestFailedOutputs(t *testing.T) {
500+
t.Parallel()
501+
502+
runner := Runner{
503+
ProjectPath: "./",
504+
Verbose: true,
505+
RunCount: 1,
506+
SelectedTestPackages: []string{flakyTestPackagePath},
507+
SelectTests: []string{"TestFail"}, // This test is known to fail consistently
508+
CollectRawOutput: true,
509+
}
510+
511+
testReport, err := runner.RunTests()
512+
require.NoError(t, err, "running tests should not produce an unexpected error")
513+
514+
require.Equal(t, 1, testReport.TestRunCount, "unexpected number of test runs")
515+
516+
var testFailResult *reports.TestResult
517+
for i := range testReport.Results {
518+
if testReport.Results[i].TestName == "TestFail" {
519+
testFailResult = &testReport.Results[i]
520+
break
521+
}
522+
}
523+
require.NotNil(t, testFailResult, "expected TestFail result not found in report")
524+
525+
require.NotEmpty(t, testFailResult.FailedOutputs, "expected failed outputs for TestFail")
526+
527+
// Verify that each run (in this case, only one) has some non-empty output
528+
for runID, outputs := range testFailResult.FailedOutputs {
529+
t.Logf("Failed outputs for run %s: %v", runID, outputs)
530+
require.NotEmpty(t, outputs, "Failed outputs should not be empty for TestFail")
531+
}
532+
}
533+
534+
func TestOmitOutputsOnSuccess(t *testing.T) {
535+
t.Parallel()
536+
537+
runner := Runner{
538+
ProjectPath: "./",
539+
Verbose: true,
540+
RunCount: 1,
541+
SelectedTestPackages: []string{flakyTestPackagePath},
542+
SelectTests: []string{"TestPass"}, // Known passing test
543+
CollectRawOutput: true,
544+
OmitOutputsOnSuccess: true,
545+
}
546+
547+
testReport, err := runner.RunTests()
548+
require.NoError(t, err, "running tests should not produce an unexpected error")
549+
550+
require.Equal(t, 1, testReport.TestRunCount, "unexpected number of test runs")
551+
552+
var testPassResult *reports.TestResult
553+
for i := range testReport.Results {
554+
if testReport.Results[i].TestName == "TestPass" {
555+
testPassResult = &testReport.Results[i]
556+
break
557+
}
558+
}
559+
require.NotNil(t, testPassResult, "expected 'TestPass' result not found in report")
560+
561+
// Since TestPass always succeeds and OmitOutputsOnSuccess is true,
562+
// we expect no PassedOutputs or general outputs.
563+
require.Empty(t, testPassResult.PassedOutputs, "expected no passed outputs due to OmitOutputsOnSuccess")
564+
require.Empty(t, testPassResult.Outputs, "expected no captured outputs due to OmitOutputsOnSuccess and a successful test")
565+
}
566+
499567
var (
500568
improperlyAttributedPanicEntries = []entry{
501569
{Action: "output", Package: "github.com/smartcontractkit/chainlink-testing-framework/tools/flakeguard/runner/example_test_package", Test: "TestFlaky", Output: "panic: This test intentionally panics [recovered]\n"},

0 commit comments

Comments
 (0)