Skip to content

Commit 9c5b07c

Browse files
committed
Reformat errors
1 parent 50da735 commit 9c5b07c

File tree

5 files changed

+44
-22
lines changed

5 files changed

+44
-22
lines changed

tools/flakeguard/Makefile

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ example:
1515
- go run . run --project-path=./runner --test-packages=./example_test_package --run-count=5 --skip-tests=Panic,Timeout --max-pass-ratio=1 --race=false --output-json=example_results/example_run_1.json
1616
- go run . run --project-path=./runner --test-packages=./example_test_package --run-count=5 --skip-tests=Panic,Timeout --max-pass-ratio=1 --race=false --output-json=example_results/example_run_2.json
1717
- go run . run --project-path=./runner --test-packages=./example_test_package --run-count=5 --skip-tests=Panic,Timeout --max-pass-ratio=1 --race=false --output-json=example_results/example_run_3.json
18-
go run . aggregate-results --results-path ./example_results --output-path ./example_results
18+
go run . aggregate-results \
19+
--results-path ./example_results \
20+
--output-path ./example_results \
21+
--repo-url "https://github.com/smartcontractkit/chainlink-testing-framework" \
22+
--base-sha "abc" \
23+
--head-sha "xyz" \
24+
--github-workflow-name "example"
1925

2026
.PHONY: example_flaky_panic
2127
example_flaky_panic:
@@ -24,7 +30,13 @@ example_flaky_panic:
2430
- go run . run --project-path=./runner --test-packages=./example_test_package --run-count=5 --skip-tests=TestPanic --max-pass-ratio=1 --race=false --output-json=example_results/example_run_1.json
2531
- go run . run --project-path=./runner --test-packages=./example_test_package --run-count=5 --skip-tests=TestPanic --max-pass-ratio=1 --race=false --output-json=example_results/example_run_2.json
2632
- go run . run --project-path=./runner --test-packages=./example_test_package --run-count=5 --skip-tests=TestPanic --max-pass-ratio=1 --race=false --output-json=example_results/example_run_3.json
27-
go run . aggregate-results --results-path ./example_results --output-path ./example_results
33+
go run . aggregate-results \
34+
--results-path ./example_results \
35+
--output-path ./example_results \
36+
--repo-url "https://github.com/smartcontractkit/chainlink-testing-framework" \
37+
--base-sha "abc" \
38+
--head-sha "xyz" \
39+
--github-workflow-name "example"
2840

2941
.PHONY: example_timeout
3042
example_timeout:
@@ -33,4 +45,10 @@ example_timeout:
3345
- go run . run --project-path=./runner --test-packages=./example_test_package --run-count=5 --select-tests=TestTimeout --timeout=1s --max-pass-ratio=1 --race=false --output-json=example_results/example_run_1.json
3446
- go run . run --project-path=./runner --test-packages=./example_test_package --run-count=5 --select-tests=TestTimeout --timeout=1s --max-pass-ratio=1 --race=false --output-json=example_results/example_run_2.json
3547
- go run . run --project-path=./runner --test-packages=./example_test_package --run-count=5 --select-tests=TestTimeout --timeout=1s --max-pass-ratio=1 --race=false --output-json=example_results/example_run_3.json
36-
go run . aggregate-results --results-path ./example_results --output-path ./example_results
48+
go run . aggregate-results \
49+
--results-path ./example_results \
50+
--output-path ./example_results \
51+
--repo-url "https://github.com/smartcontractkit/chainlink-testing-framework" \
52+
--base-sha "abc" \
53+
--head-sha "xyz" \
54+
--github-workflow-name "example"

tools/flakeguard/cmd/aggregate_results.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ var AggregateResultsCmd = &cobra.Command{
138138
}
139139
log.Info().Str("path", failedTestsReportNoLogsPath).Msg("Failed tests report without logs saved")
140140
} else {
141-
log.Info().Msg("No failed tests found. Skipping generation of failed tests reports")
141+
log.Debug().Msg("No failed tests found. Skipping generation of failed tests reports")
142142
}
143143

144144
// Remove logs from test results for the aggregated report
@@ -171,7 +171,7 @@ var AggregateResultsCmd = &cobra.Command{
171171
log.Info().Str("path", summaryFilePath).Msg("Summary generated")
172172
}
173173

174-
log.Info().Str("path", outputDir).Msg("Aggregation complete")
174+
log.Info().Msg("Aggregation complete")
175175
return nil
176176
},
177177
}

tools/flakeguard/cmd/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ var RunTestsCmd = &cobra.Command{
9696
})
9797

9898
if len(flakyTests) > 0 {
99-
log.Info().Int("count", len(flakyTests)).Str("pass ratio threshold", fmt.Sprintf("%.2f%%", maxPassRatio)).Msg("Found flaky tests")
99+
log.Info().Int("count", len(flakyTests)).Str("pass ratio threshold", fmt.Sprintf("%.2f%%", maxPassRatio*100)).Msg("Found flaky tests")
100100
fmt.Printf("\nFlakeguard Summary\n")
101101
reports.RenderResults(os.Stdout, flakyTests, maxPassRatio, false)
102102
// Exit with error code if there are flaky tests

tools/flakeguard/reports/data.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ func FilterTests(results []TestResult, predicate func(TestResult) bool) []TestRe
174174
return filtered
175175
}
176176

177-
func aggregate(reportChan <-chan *TestReport, opts *aggregateOptions) (*TestReport, error) {
177+
func aggregate(reportChan <-chan *TestReport, errChan <-chan error, opts *aggregateOptions) (*TestReport, error) {
178178
testMap := make(map[string]TestResult)
179179
fullReport := &TestReport{}
180180
excludedTests := map[string]struct{}{}
@@ -206,6 +206,10 @@ func aggregate(reportChan <-chan *TestReport, opts *aggregateOptions) (*TestRepo
206206
}
207207
}
208208

209+
for err := range errChan {
210+
return nil, err
211+
}
212+
209213
// Finalize excluded and selected tests
210214
for test := range excludedTests {
211215
fullReport.ExcludedTests = append(fullReport.ExcludedTests, test)
@@ -228,11 +232,13 @@ func aggregate(reportChan <-chan *TestReport, opts *aggregateOptions) (*TestRepo
228232

229233
func aggregateFromReports(opts *aggregateOptions, reports ...*TestReport) (*TestReport, error) {
230234
reportChan := make(chan *TestReport, len(reports))
235+
errChan := make(chan error, 1)
231236
for _, report := range reports {
232237
reportChan <- report
233238
}
234239
close(reportChan)
235-
return aggregate(reportChan, opts)
240+
close(errChan)
241+
return aggregate(reportChan, errChan, opts)
236242
}
237243

238244
func mergeTestResults(a, b TestResult) TestResult {

tools/flakeguard/reports/io.go

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ func LoadAndAggregate(resultsPath string, options ...AggregateOption) (*TestRepo
8383
}
8484
if !info.IsDir() && filepath.Ext(path) == ".json" {
8585
log.Debug().Str("path", path).Msg("Processing file")
86-
processLargeFile(path, reportChan, errChan)
86+
err = processLargeFile(path, reportChan)
87+
if err != nil {
88+
return fmt.Errorf("error processing file '%s': %w", path, err)
89+
}
8790
}
8891
return nil
8992
})
@@ -99,21 +102,20 @@ func LoadAndAggregate(resultsPath string, options ...AggregateOption) (*TestRepo
99102
}
100103
opts.reportID = uuid.String()
101104
}
105+
102106
// Aggregate results as they are being loaded
103-
aggregatedReport, err := aggregate(reportChan, &opts)
107+
aggregatedReport, err := aggregate(reportChan, errChan, &opts)
104108
if err != nil {
105109
return nil, fmt.Errorf("error aggregating reports: %w", err)
106110
}
107111
return aggregatedReport, nil
108112
}
109113

110114
// processLargeFile reads a large JSON report file and creates TestReport objects in a memory-efficient way.
111-
func processLargeFile(filePath string, reportChan chan<- *TestReport, errChan chan<- error) {
115+
func processLargeFile(filePath string, reportChan chan<- *TestReport) error {
112116
file, err := os.Open(filePath)
113117
if err != nil {
114-
errChan <- fmt.Errorf("error opening file %s: %w", filePath, err)
115-
log.Printf("Error opening file: %s, Error: %v", filePath, err)
116-
return
118+
return fmt.Errorf("error opening file: %w", err)
117119
}
118120
defer file.Close()
119121

@@ -122,27 +124,23 @@ func processLargeFile(filePath string, reportChan chan<- *TestReport, errChan ch
122124
var report TestReport
123125
token, err := decoder.Token() // Read opening brace '{'
124126
if err != nil || token != json.Delim('{') {
125-
errChan <- fmt.Errorf("error reading JSON object start from file %s: %w", filePath, err)
126-
log.Printf("Error reading JSON object start from file: %s, Error: %v", filePath, err)
127-
return
127+
return fmt.Errorf("error reading JSON object start from file: %w", err)
128128
}
129129

130130
// Parse fields until we reach the end of the object
131131
for decoder.More() {
132132
if err = decodeField(decoder, report); err != nil {
133-
errChan <- fmt.Errorf("error decoding field: %w", err)
134-
log.Printf("Error decoding file '%s': %v", filePath, err)
135-
return
133+
return fmt.Errorf("error decoding field: %w", err)
136134
}
137135
}
138136

139137
// Read closing brace '}'
140138
if _, err := decoder.Token(); err != nil {
141-
log.Printf("Error reading JSON object end in file: %s, Error: %v", filePath, err)
142-
return
139+
return fmt.Errorf("error reading JSON object end from file: %w", err)
143140
}
144141

145142
reportChan <- &report
143+
return nil
146144
}
147145

148146
// decodeField reads a JSON field from the decoder and populates the corresponding field in the TestReport.

0 commit comments

Comments
 (0)