Skip to content

Commit 60ea174

Browse files
committed
Improves and standardizes Flakeguard summary data
1 parent 0bc54cd commit 60ea174

File tree

17 files changed

+1466
-1260
lines changed

17 files changed

+1466
-1260
lines changed

tools/flakeguard/cmd/aggregate_results.go

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ var AggregateResultsCmd = &cobra.Command{
4747
s := spinner.New(spinner.CharSets[11], 100*time.Millisecond)
4848
s.Suffix = " Aggregating test reports..."
4949
s.Start()
50+
fmt.Println()
5051

5152
// Load test reports from JSON files and aggregate them
5253
aggregatedReport, err := reports.LoadAndAggregate(
@@ -62,12 +63,10 @@ var AggregateResultsCmd = &cobra.Command{
6263
)
6364
if err != nil {
6465
s.Stop()
65-
fmt.Println()
66-
log.Error().Err(err).Msg("Error aggregating test reports")
66+
log.Error().Err(err).Stack().Msg("Error aggregating test reports")
6767
os.Exit(ErrorExitCode)
6868
}
6969
s.Stop()
70-
fmt.Println()
7170
log.Debug().Msg("Successfully loaded and aggregated test reports")
7271

7372
// Start spinner for mapping test results to paths
@@ -79,37 +78,33 @@ var AggregateResultsCmd = &cobra.Command{
7978
err = reports.MapTestResultsToPaths(aggregatedReport, repoPath)
8079
if err != nil {
8180
s.Stop()
82-
fmt.Println()
83-
log.Error().Err(err).Msg("Error mapping test results to paths")
81+
log.Error().Stack().Err(err).Msg("Error mapping test results to paths")
8482
os.Exit(ErrorExitCode)
8583
}
8684
s.Stop()
87-
fmt.Println()
8885
log.Debug().Msg("Successfully mapped paths to test results")
8986

9087
// Map test results to code owners if codeOwnersPath is provided
9188
if codeOwnersPath != "" {
9289
s = spinner.New(spinner.CharSets[11], 100*time.Millisecond)
9390
s.Suffix = " Mapping test results to code owners..."
9491
s.Start()
92+
fmt.Println()
9593

9694
err = reports.MapTestResultsToOwners(aggregatedReport, codeOwnersPath)
9795
if err != nil {
9896
s.Stop()
99-
fmt.Println()
100-
log.Error().Err(err).Msg("Error mapping test results to code owners")
97+
log.Error().Stack().Err(err).Msg("Error mapping test results to code owners")
10198
os.Exit(ErrorExitCode)
10299
}
103100
s.Stop()
104-
fmt.Println()
105101
log.Debug().Msg("Successfully mapped code owners to test results")
106102
}
107103

108104
failedTests := reports.FilterTests(aggregatedReport.Results, func(tr reports.TestResult) bool {
109105
return !tr.Skipped && tr.PassRatio < maxPassRatio
110106
})
111107
s.Stop()
112-
fmt.Println()
113108

114109
// Check if there are any failed tests
115110
if len(failedTests) > 0 {
@@ -118,7 +113,7 @@ var AggregateResultsCmd = &cobra.Command{
118113
// Create a new report for failed tests with logs
119114
failedReportWithLogs := &reports.TestReport{
120115
GoProject: aggregatedReport.GoProject,
121-
TestRunCount: aggregatedReport.TestRunCount,
116+
SummaryData: aggregatedReport.SummaryData,
122117
RaceDetection: aggregatedReport.RaceDetection,
123118
ExcludedTests: aggregatedReport.ExcludedTests,
124119
SelectedTests: aggregatedReport.SelectedTests,
@@ -131,7 +126,7 @@ var AggregateResultsCmd = &cobra.Command{
131126
// Save the failed tests report with logs
132127
failedTestsReportWithLogsPath := filepath.Join(outputDir, "failed-test-results-with-logs.json")
133128
if err := reports.SaveReport(fs, failedTestsReportWithLogsPath, *failedReportWithLogs); err != nil {
134-
log.Error().Err(err).Msg("Error saving failed tests report with logs")
129+
log.Error().Stack().Err(err).Msg("Error saving failed tests report with logs")
135130
os.Exit(ErrorExitCode)
136131
}
137132
log.Debug().Str("path", failedTestsReportWithLogsPath).Msg("Failed tests report with logs saved")
@@ -146,7 +141,7 @@ var AggregateResultsCmd = &cobra.Command{
146141
// Save the failed tests report without logs
147142
failedTestsReportNoLogsPath := filepath.Join(outputDir, "failed-test-results.json")
148143
if err := reports.SaveReport(fs, failedTestsReportNoLogsPath, *failedReportWithLogs); err != nil {
149-
log.Error().Err(err).Msg("Error saving failed tests report without logs")
144+
log.Error().Stack().Err(err).Msg("Error saving failed tests report without logs")
150145
os.Exit(ErrorExitCode)
151146
}
152147
log.Debug().Str("path", failedTestsReportNoLogsPath).Msg("Failed tests report without logs saved")
@@ -164,7 +159,7 @@ var AggregateResultsCmd = &cobra.Command{
164159
// Save the aggregated report to the output directory
165160
aggregatedReportPath := filepath.Join(outputDir, "all-test-results.json")
166161
if err := reports.SaveReport(fs, aggregatedReportPath, *aggregatedReport); err != nil {
167-
log.Error().Err(err).Msg("Error saving aggregated test report")
162+
log.Error().Stack().Err(err).Msg("Error saving aggregated test report")
168163
os.Exit(ErrorExitCode)
169164
}
170165
log.Debug().Str("path", aggregatedReportPath).Msg("Aggregated test report saved")
@@ -175,17 +170,17 @@ var AggregateResultsCmd = &cobra.Command{
175170
s = spinner.New(spinner.CharSets[11], 100*time.Millisecond)
176171
s.Suffix = " Generating summary json..."
177172
s.Start()
173+
fmt.Println()
178174

179175
summaryFilePath = filepath.Join(outputDir, summaryFileName)
180176
err = generateAllTestsSummaryJSON(aggregatedReport, summaryFilePath, maxPassRatio)
181177
if err != nil {
182178
s.Stop()
183179
fmt.Println()
184-
log.Error().Err(err).Msg("Error generating summary json")
180+
log.Error().Stack().Err(err).Msg("Error generating summary json")
185181
os.Exit(ErrorExitCode)
186182
}
187183
s.Stop()
188-
fmt.Println()
189184
log.Debug().Str("path", summaryFilePath).Msg("Summary generated")
190185
}
191186

tools/flakeguard/cmd/generate_report.go

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,9 @@ import (
1717
"golang.org/x/oauth2"
1818
)
1919

20-
type SummaryData struct {
21-
TotalTests int `json:"total_tests"`
22-
PanickedTests int `json:"panicked_tests"`
23-
RacedTests int `json:"raced_tests"`
24-
FlakyTests int `json:"flaky_tests"`
25-
FlakyTestRatio string `json:"flaky_test_ratio"`
26-
TotalRuns int `json:"total_runs"`
27-
PassedRuns int `json:"passed_runs"`
28-
FailedRuns int `json:"failed_runs"`
29-
SkippedRuns int `json:"skipped_runs"`
30-
PassRatio string `json:"pass_ratio"`
31-
MaxPassRatio float64 `json:"max_pass_ratio"`
32-
}
33-
3420
var GenerateReportCmd = &cobra.Command{
3521
Use: "generate-report",
36-
Short: "Generate reports from an aggregated test results",
22+
Short: "Generate test reports from aggregated results that can be posted to GitHub",
3723
Run: func(cmd *cobra.Command, args []string) {
3824
fs := reports.OSFileSystem{}
3925

@@ -80,7 +66,7 @@ var GenerateReportCmd = &cobra.Command{
8066
log.Info().Msg("Successfully loaded aggregated test report")
8167

8268
// Load the summary data to check for failed tests
83-
var summaryData SummaryData
69+
var summaryData reports.SummaryData
8470

8571
if summaryPath == "" {
8672
log.Error().Msg("Summary path is required")

tools/flakeguard/cmd/run.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ var RunTestsCmd = &cobra.Command{
4040
shuffleSeed, _ := cmd.Flags().GetString("shuffle-seed")
4141
omitOutputsOnSuccess, _ := cmd.Flags().GetBool("omit-test-outputs-on-success")
4242

43+
if maxPassRatio < 0 || maxPassRatio > 1 {
44+
log.Error().Float64("max pass ratio", maxPassRatio).Msg("Error: max pass ratio must be between 0 and 1")
45+
os.Exit(ErrorExitCode)
46+
}
47+
4348
// Check if project dependencies are correctly set up
4449
if err := checkDependencies(projectPath); err != nil {
4550
log.Error().Err(err).Msg("Error checking project dependencies")
@@ -74,6 +79,7 @@ var RunTestsCmd = &cobra.Command{
7479
UseShuffle: useShuffle,
7580
ShuffleSeed: shuffleSeed,
7681
OmitOutputsOnSuccess: omitOutputsOnSuccess,
82+
MaxPassRatio: maxPassRatio,
7783
}
7884

7985
// Run the tests
@@ -107,10 +113,10 @@ var RunTestsCmd = &cobra.Command{
107113
return !tr.Skipped && tr.PassRatio < maxPassRatio
108114
})
109115

116+
fmt.Printf("\nFlakeguard Summary\n")
117+
reports.RenderResults(os.Stdout, flakyTests, maxPassRatio, false, false)
110118
if len(flakyTests) > 0 {
111119
log.Info().Int("count", len(flakyTests)).Str("pass ratio threshold", fmt.Sprintf("%.2f%%", maxPassRatio*100)).Msg("Found flaky tests")
112-
fmt.Printf("\nFlakeguard Summary\n")
113-
reports.RenderResults(os.Stdout, flakyTests, maxPassRatio, false, false)
114120
// Exit with error code if there are flaky tests
115121
os.Exit(FlakyTestsExitCode)
116122
}

tools/flakeguard/go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/smartcontractkit/chainlink-testing-framework/tools/flakeguard
22

3-
go 1.23.4
3+
go 1.23.6
44

55
require (
66
github.com/briandowns/spinner v1.23.1
@@ -21,6 +21,7 @@ require (
2121
github.com/inconshreveable/mousetrap v1.1.0 // indirect
2222
github.com/mattn/go-colorable v0.1.13 // indirect
2323
github.com/mattn/go-isatty v0.0.19 // indirect
24+
github.com/pkg/errors v0.9.1 // indirect
2425
github.com/pmezard/go-difflib v1.0.0 // indirect
2526
github.com/spf13/pflag v1.0.5 // indirect
2627
golang.org/x/net v0.27.0 // indirect

tools/flakeguard/go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk
2525
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
2626
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
2727
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
28+
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
2829
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
2930
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
3031
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=

tools/flakeguard/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/rs/zerolog"
88
"github.com/rs/zerolog/log"
9+
"github.com/rs/zerolog/pkgerrors"
910
"github.com/spf13/cobra"
1011

1112
"github.com/smartcontractkit/chainlink-testing-framework/tools/flakeguard/cmd"
@@ -32,6 +33,7 @@ func init() {
3233
Out: os.Stderr,
3334
TimeFormat: "15:04:05.00", // hh:mm:ss.ss format
3435
})
36+
zerolog.ErrorStackMarshaler = pkgerrors.MarshalStack
3537
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
3638

3739
rootCmd.AddCommand(cmd.FindTestsCmd)

0 commit comments

Comments
 (0)