Skip to content

Commit f3ba07c

Browse files
committed
Fixes
1 parent 4152192 commit f3ba07c

File tree

3 files changed

+15
-18
lines changed

3 files changed

+15
-18
lines changed

tools/flakeguard/cmd/aggregate_results.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,5 @@ func init() {
5050
AggregateResultsCmd.Flags().StringVarP(&outputResultsPath, "output-results", "o", "./results.json", "Path to output the aggregated or filtered test results in JSON format")
5151
AggregateResultsCmd.Flags().StringVarP(&outputLogsPath, "output-logs", "l", "", "Path to output the filtered test logs in JSON format")
5252
AggregateResultsCmd.Flags().Float64VarP(&maxPassRatio, "max-pass-ratio", "m", 1.0, "The maximum (non-inclusive) pass ratio threshold for a test to be considered a failure. Any tests below this pass rate will be considered flaky.")
53-
AggregateResultsCmd.Flags().BoolVarP(&filterFailed, "filter-failed", "f", false, "If true, filter and output only failed tests based on the min-pass-ratio threshold")
53+
AggregateResultsCmd.Flags().BoolVarP(&filterFailed, "filter-failed", "f", false, "If true, filter and output only failed tests based on the max-pass-ratio threshold")
5454
}

tools/flakeguard/cmd/run.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ var RunTestsCmd = &cobra.Command{
2323
runCount, _ := cmd.Flags().GetInt("run-count")
2424
useRace, _ := cmd.Flags().GetBool("race")
2525
outputPath, _ := cmd.Flags().GetString("output-json")
26-
threshold, _ := cmd.Flags().GetFloat64("threshold")
26+
maxPassRatio, _ := cmd.Flags().GetFloat64("max-pass-ratio")
2727
skipTests, _ := cmd.Flags().GetStringSlice("skip-tests")
2828
printFailedTests, _ := cmd.Flags().GetBool("print-failed-tests")
29-
minPassRatio, _ := cmd.Flags().GetFloat64("min-pass-ratio")
3029

3130
// Check if project dependencies are correctly set up
3231
if err := checkDependencies(projectPath); err != nil {
@@ -59,15 +58,15 @@ var RunTestsCmd = &cobra.Command{
5958
os.Exit(1)
6059
}
6160

62-
passedTests := reports.FilterPassedTests(testResults, threshold)
63-
failedTests := reports.FilterFailedTests(testResults, threshold)
61+
passedTests := reports.FilterPassedTests(testResults, maxPassRatio)
62+
failedTests := reports.FilterFailedTests(testResults, maxPassRatio)
6463
skippedTests := reports.FilterSkippedTests(testResults)
65-
flakyTests := reports.FilterFlakyTests(testResults, minPassRatio, threshold)
64+
flakyTests := reports.FilterFlakyTests(testResults, maxPassRatio)
6665

6766
// Print all failed tests including flaky tests
6867
if len(failedTests) > 0 && printFailedTests {
69-
fmt.Printf("MinPassRatio threshold for flaky tests: %.2f\n", minPassRatio)
70-
fmt.Printf("PassRatio threshold for flaky tests: %.2f\n", threshold)
68+
fmt.Printf("Maximum threshold for flaky tests: %.2f\n", maxPassRatio)
69+
fmt.Printf("PassRatio threshold for flaky tests: %.2f\n", maxPassRatio)
7170
fmt.Printf("%d failed tests:\n", len(failedTests))
7271
reports.PrintTests(failedTests, os.Stdout)
7372
}
@@ -104,10 +103,9 @@ func init() {
104103
RunTestsCmd.Flags().Bool("race", false, "Enable the race detector")
105104
RunTestsCmd.Flags().Bool("fail-fast", false, "Stop on the first test failure")
106105
RunTestsCmd.Flags().String("output-json", "", "Path to output the test results in JSON format")
107-
RunTestsCmd.Flags().Float64("threshold", 0.8, "Threshold for considering a test as flaky")
108106
RunTestsCmd.Flags().StringSlice("skip-tests", nil, "Comma-separated list of test names to skip from running")
109107
RunTestsCmd.Flags().Bool("print-failed-tests", true, "Print failed test results to the console")
110-
RunTestsCmd.Flags().Float64("min-pass-ratio", 0.001, "Minimum pass ratio for considering a test as flaky. Used to distinguish between tests that are truly flaky (with inconsistent results) and those that are consistently failing.")
108+
RunTestsCmd.Flags().Float64("max-pass-ratio", 1.0, "The maximum (non-inclusive) pass ratio threshold for a test to be considered a failure. Any tests below this pass rate will be considered flaky.")
111109
}
112110

113111
func checkDependencies(projectPath string) error {

tools/flakeguard/reports/reports.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,32 +33,32 @@ type TestResult struct {
3333
}
3434

3535
// FilterFailedTests returns a slice of TestResult where the pass ratio is below the specified threshold.
36-
func FilterFailedTests(results []TestResult, threshold float64) []TestResult {
36+
func FilterFailedTests(results []TestResult, maxPassRatio float64) []TestResult {
3737
var failedTests []TestResult
3838
for _, result := range results {
39-
if !result.Skipped && result.PassRatio < threshold {
39+
if !result.Skipped && result.PassRatio < maxPassRatio {
4040
failedTests = append(failedTests, result)
4141
}
4242
}
4343
return failedTests
4444
}
4545

4646
// FilterFlakyTests returns a slice of TestResult where the pass ratio is between the min pass ratio and the threshold.
47-
func FilterFlakyTests(testResults []TestResult, minPassRatio, threshold float64) []TestResult {
47+
func FilterFlakyTests(testResults []TestResult, maxPassRatio float64) []TestResult {
4848
var flakyTests []TestResult
4949
for _, test := range testResults {
50-
if test.PassRatio >= minPassRatio && test.PassRatio < threshold && !test.Skipped {
50+
if test.PassRatio < maxPassRatio && !test.Skipped {
5151
flakyTests = append(flakyTests, test)
5252
}
5353
}
5454
return flakyTests
5555
}
5656

5757
// FilterPassedTests returns a slice of TestResult where the tests passed and were not skipped.
58-
func FilterPassedTests(results []TestResult, threshold float64) []TestResult {
58+
func FilterPassedTests(results []TestResult, maxPassRatio float64) []TestResult {
5959
var passedTests []TestResult
6060
for _, result := range results {
61-
if !result.Skipped && result.PassRatio >= threshold {
61+
if !result.Skipped && result.PassRatio >= maxPassRatio {
6262
passedTests = append(passedTests, result)
6363
}
6464
}
@@ -142,7 +142,6 @@ func AggregateTestResults(folderPath string) ([]TestResult, error) {
142142
}
143143

144144
// PrintTests prints tests in a pretty format
145-
// TODO: Update this with new fields
146145
func PrintTests(tests []TestResult, w io.Writer) {
147146
for i, test := range tests {
148147
fmt.Fprintf(w, "\n--- Test %d ---\n", i+1)
@@ -184,7 +183,7 @@ func SaveFilteredResultsAndLogs(outputResultsPath, outputLogsPath string, failed
184183
}
185184
}
186185

187-
// Helper function to save results to JSON file
186+
// Helper function to save results to JSON file without outputs
188187
func saveResults(filePath string, results []TestResult) error {
189188
var filteredResults []TestResult
190189
for _, r := range results {

0 commit comments

Comments
 (0)