Skip to content

Commit 8b02ed1

Browse files
authored
flakeguard: TT-1853 Create json file with metadata for all test results (#1361)
1 parent 0dd918b commit 8b02ed1

File tree

5 files changed

+57
-85
lines changed

5 files changed

+57
-85
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() {

tools/flakeguard/runner/runner.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,15 @@ type exitCoder interface {
5555
// runTests runs the tests for a given package and returns the path to the output file.
5656
func (r *Runner) runTests(packageName string) (string, bool, error) {
5757
args := []string{"test", packageName, "-json", "-count=1"} // Enable JSON output
58-
args = append(args, "2>/dev/null") // Redirect stderr to null
5958
if r.UseRace {
6059
args = append(args, "-race")
6160
}
6261
if len(r.SkipTests) > 0 {
6362
skipPattern := strings.Join(r.SkipTests, "|")
6463
args = append(args, fmt.Sprintf("-skip=%s", skipPattern))
6564
}
65+
// The last arg redirects stderr to null
66+
args = append(args, "2>/dev/null")
6667

6768
if r.Verbose {
6869
log.Printf("Running command: go %s\n", strings.Join(args, " "))

0 commit comments

Comments
 (0)