Skip to content

Commit eb3f15a

Browse files
committed
Add aggregate-results cmd
1 parent 0dd918b commit eb3f15a

File tree

4 files changed

+55
-84
lines changed

4 files changed

+55
-84
lines changed

tools/flakeguard/cmd/aggregate_all.go

Lines changed: 0 additions & 35 deletions
This file was deleted.

tools/flakeguard/cmd/aggregate_failed.go

Lines changed: 0 additions & 47 deletions
This file was deleted.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package cmd
2+
3+
import (
4+
"log"
5+
6+
"github.com/smartcontractkit/chainlink-testing-framework/tools/flakeguard/reports"
7+
"github.com/spf13/cobra"
8+
)
9+
10+
var AggregateResultsCmd = &cobra.Command{
11+
Use: "aggregate-results",
12+
Short: "Aggregate test results and optionally filter failed tests based on a threshold",
13+
Run: func(cmd *cobra.Command, args []string) {
14+
resultsFolderPath, _ := cmd.Flags().GetString("results-path")
15+
outputResultsPath, _ := cmd.Flags().GetString("output-results")
16+
outputLogsPath, _ := cmd.Flags().GetString("output-logs")
17+
threshold, _ := cmd.Flags().GetFloat64("threshold")
18+
minPassRatio, _ := cmd.Flags().GetFloat64("min-pass-ratio")
19+
filterFailed, _ := cmd.Flags().GetBool("filter-failed")
20+
21+
// Aggregate all test results
22+
allResults, err := reports.AggregateTestResults(resultsFolderPath)
23+
if err != nil {
24+
log.Fatalf("Error aggregating results: %v", err)
25+
}
26+
27+
var resultsToSave []reports.TestResult
28+
29+
if filterFailed {
30+
// Filter to only include failed tests based on threshold and minPassRatio
31+
for _, result := range allResults {
32+
if result.PassRatio < threshold && result.PassRatio > minPassRatio && !result.Skipped {
33+
resultsToSave = append(resultsToSave, result)
34+
}
35+
}
36+
} else {
37+
resultsToSave = allResults
38+
}
39+
40+
// Output results to JSON files
41+
if len(resultsToSave) > 0 {
42+
reports.SaveFilteredResultsAndLogs(outputResultsPath, outputLogsPath, resultsToSave)
43+
}
44+
},
45+
}
46+
47+
func init() {
48+
AggregateResultsCmd.Flags().String("results-path", "", "Path to the folder containing JSON test result files")
49+
AggregateResultsCmd.Flags().String("output-results", "./results.json", "Path to output the aggregated or filtered test results in JSON format")
50+
AggregateResultsCmd.Flags().String("output-logs", "", "Path to output the filtered test logs in JSON format")
51+
AggregateResultsCmd.Flags().Float64("threshold", 0.8, "Threshold for considering a test as failed (used with --filter-failed)")
52+
AggregateResultsCmd.Flags().Float64("min-pass-ratio", 0.001, "Minimum pass ratio for considering a test as flaky (used with --filter-failed)")
53+
AggregateResultsCmd.Flags().Bool("filter-failed", false, "If true, filter and output only failed tests based on the threshold")
54+
}

tools/flakeguard/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ func init() {
2828

2929
rootCmd.AddCommand(cmd.FindTestsCmd)
3030
rootCmd.AddCommand(cmd.RunTestsCmd)
31-
rootCmd.AddCommand(cmd.AggregateAllCmd)
32-
rootCmd.AddCommand(cmd.AggregateFailedCmd)
31+
rootCmd.AddCommand(cmd.AggregateResultsCmd)
3332
}
3433

3534
func main() {

0 commit comments

Comments
 (0)