Skip to content

Commit 694e599

Browse files
committed
fix
1 parent 19e4da7 commit 694e599

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

tools/flakeguard/cmd/run.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ var RunTestsCmd = &cobra.Command{
2929
maxPassRatio, _ := cmd.Flags().GetFloat64("max-pass-ratio")
3030
skipTests, _ := cmd.Flags().GetStringSlice("skip-tests")
3131
selectTests, _ := cmd.Flags().GetStringSlice("select-tests")
32-
printFailedTests, _ := cmd.Flags().GetBool("print-failed-tests")
3332
useShuffle, _ := cmd.Flags().GetBool("shuffle")
3433
shuffleSeed, _ := cmd.Flags().GetString("shuffle-seed")
3534

@@ -84,10 +83,17 @@ var RunTestsCmd = &cobra.Command{
8483
fmt.Printf("All test results saved to %s\n", outputPath)
8584
}
8685

87-
// Print all failed tests including flaky tests
88-
if printFailedTests {
86+
// Filter flaky tests using FilterTests
87+
flakyTests := reports.FilterTests(testReport.Results, func(tr reports.TestResult) bool {
88+
return !tr.Skipped && tr.PassRatio < maxPassRatio
89+
})
90+
91+
if len(flakyTests) > 0 {
92+
fmt.Printf("Found %d flaky tests below the pass ratio threshold of %.2f:\n", len(flakyTests), maxPassRatio)
8993
fmt.Printf("\nFlakeguard Summary\n")
90-
reports.RenderResults(os.Stdout, testReport.Results, maxPassRatio, false)
94+
reports.RenderResults(os.Stdout, flakyTests, maxPassRatio, false)
95+
// Exit with error code if there are flaky tests
96+
os.Exit(1)
9197
}
9298
},
9399
}
@@ -107,7 +113,6 @@ func init() {
107113
RunTestsCmd.Flags().String("output-json", "", "Path to output the test results in JSON format")
108114
RunTestsCmd.Flags().StringSlice("skip-tests", nil, "Comma-separated list of test names to skip from running")
109115
RunTestsCmd.Flags().StringSlice("select-tests", nil, "Comma-separated list of test names to specifically run")
110-
RunTestsCmd.Flags().Bool("print-failed-tests", true, "Print failed test results to the console")
111116
RunTestsCmd.Flags().Float64("max-pass-ratio", 1.0, "The maximum pass ratio threshold for a test to be considered flaky. Any tests below this pass rate will be considered flaky.")
112117
}
113118

0 commit comments

Comments
 (0)