Skip to content

Commit 0dd02ae

Browse files
authored
Merge branch 'main' into tt-1725-update-go-doc-generation-env-var
2 parents 2d874a3 + ea4ffd8 commit 0dd02ae

File tree

6 files changed

+224
-103
lines changed

6 files changed

+224
-103
lines changed

tools/flakeguard/cmd/aggregate_results.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ var AggregateResultsCmd = &cobra.Command{
121121

122122
// Remove logs from test results for the report without logs
123123
for i := range failedReportWithLogs.Results {
124-
failedReportWithLogs.Results[i].Outputs = nil
124+
failedReportWithLogs.Results[i].PassedOutputs = nil
125+
failedReportWithLogs.Results[i].FailedOutputs = nil
125126
failedReportWithLogs.Results[i].PackageOutputs = nil
126127
}
127128

@@ -137,7 +138,8 @@ var AggregateResultsCmd = &cobra.Command{
137138

138139
// Remove logs from test results for the aggregated report
139140
for i := range aggregatedReport.Results {
140-
aggregatedReport.Results[i].Outputs = nil
141+
aggregatedReport.Results[i].PassedOutputs = nil
142+
aggregatedReport.Results[i].FailedOutputs = nil
141143
aggregatedReport.Results[i].PackageOutputs = nil
142144
}
143145

tools/flakeguard/reports/data.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ type TestResult struct {
3636
Failures int
3737
Successes int
3838
Skips int
39-
Outputs []string
39+
Outputs map[string][]string `json:"-"` // Temporary storage for outputs during test run
40+
PassedOutputs map[string][]string // Outputs for passed runs
41+
FailedOutputs map[string][]string // Outputs for failed runs
4042
Durations []time.Duration
4143
PackageOutputs []string
4244
TestPath string
@@ -191,7 +193,18 @@ func aggregateFromReports(reports ...*TestReport) (*TestReport, error) {
191193
func mergeTestResults(a, b TestResult) TestResult {
192194
a.Runs += b.Runs
193195
a.Durations = append(a.Durations, b.Durations...)
194-
a.Outputs = append(a.Outputs, b.Outputs...)
196+
if a.PassedOutputs == nil {
197+
a.PassedOutputs = make(map[string][]string)
198+
}
199+
if a.FailedOutputs == nil {
200+
a.FailedOutputs = make(map[string][]string)
201+
}
202+
for runID, outputs := range b.PassedOutputs {
203+
a.PassedOutputs[runID] = append(a.PassedOutputs[runID], outputs...)
204+
}
205+
for runID, outputs := range b.FailedOutputs {
206+
a.FailedOutputs[runID] = append(a.FailedOutputs[runID], outputs...)
207+
}
195208
a.PackageOutputs = append(a.PackageOutputs, b.PackageOutputs...)
196209
a.Successes += b.Successes
197210
a.Failures += b.Failures

tools/flakeguard/reports/data_test.go

Lines changed: 43 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -346,11 +346,13 @@ func TestAggregateOutputs(t *testing.T) {
346346
TestRunCount: 1,
347347
Results: []TestResult{
348348
{
349-
TestName: "TestOutput",
350-
TestPackage: "pkg1",
351-
Runs: 1,
352-
Successes: 1,
353-
Outputs: []string{"Output from report1 test run"},
349+
TestName: "TestOutput",
350+
TestPackage: "pkg1",
351+
Runs: 1,
352+
Successes: 1,
353+
PassedOutputs: map[string][]string{
354+
"run1": {"Output from report1 test run"},
355+
},
354356
PackageOutputs: []string{"Package output from report1"},
355357
},
356358
},
@@ -361,11 +363,13 @@ func TestAggregateOutputs(t *testing.T) {
361363
TestRunCount: 1,
362364
Results: []TestResult{
363365
{
364-
TestName: "TestOutput",
365-
TestPackage: "pkg1",
366-
Runs: 1,
367-
Successes: 1,
368-
Outputs: []string{"Output from report2 test run"},
366+
TestName: "TestOutput",
367+
TestPackage: "pkg1",
368+
Runs: 1,
369+
Successes: 1,
370+
PassedOutputs: map[string][]string{
371+
"run2": {"Output from report2 test run"},
372+
},
369373
PackageOutputs: []string{"Package output from report2"},
370374
},
371375
},
@@ -382,18 +386,22 @@ func TestAggregateOutputs(t *testing.T) {
382386

383387
result := aggregatedReport.Results[0]
384388

385-
// Expected outputs
386-
expectedOutputs := []string{
387-
"Output from report1 test run",
388-
"Output from report2 test run",
389+
expectedOutputs := map[string][]string{
390+
"run1": {
391+
"Output from report1 test run",
392+
},
393+
"run2": {
394+
"Output from report2 test run",
395+
},
389396
}
397+
390398
expectedPackageOutputs := []string{
391399
"Package output from report1",
392400
"Package output from report2",
393401
}
394402

395-
if !reflect.DeepEqual(result.Outputs, expectedOutputs) {
396-
t.Errorf("Expected Outputs %v, got %v", expectedOutputs, result.Outputs)
403+
if !reflect.DeepEqual(result.PassedOutputs, expectedOutputs) {
404+
t.Errorf("Expected Outputs %v, got %v", expectedOutputs, result.PassedOutputs)
397405
}
398406

399407
if !reflect.DeepEqual(result.PackageOutputs, expectedPackageOutputs) {
@@ -407,11 +415,13 @@ func TestAggregateIdenticalOutputs(t *testing.T) {
407415
TestRunCount: 1,
408416
Results: []TestResult{
409417
{
410-
TestName: "TestIdenticalOutput",
411-
TestPackage: "pkg1",
412-
Runs: 1,
413-
Successes: 1,
414-
Outputs: []string{"Identical output"},
418+
TestName: "TestIdenticalOutput",
419+
TestPackage: "pkg1",
420+
Runs: 1,
421+
Successes: 1,
422+
PassedOutputs: map[string][]string{
423+
"run1": {"Identical output"},
424+
},
415425
PackageOutputs: []string{"Identical package output"},
416426
},
417427
},
@@ -422,11 +432,13 @@ func TestAggregateIdenticalOutputs(t *testing.T) {
422432
TestRunCount: 1,
423433
Results: []TestResult{
424434
{
425-
TestName: "TestIdenticalOutput",
426-
TestPackage: "pkg1",
427-
Runs: 1,
428-
Successes: 1,
429-
Outputs: []string{"Identical output"},
435+
TestName: "TestIdenticalOutput",
436+
TestPackage: "pkg1",
437+
Runs: 1,
438+
Successes: 1,
439+
PassedOutputs: map[string][]string{
440+
"run1": {"Identical output"},
441+
},
430442
PackageOutputs: []string{"Identical package output"},
431443
},
432444
},
@@ -443,80 +455,24 @@ func TestAggregateIdenticalOutputs(t *testing.T) {
443455

444456
result := aggregatedReport.Results[0]
445457

446-
// Expected outputs
447-
expectedOutputs := []string{
448-
"Identical output",
449-
"Identical output",
458+
expectedOutputs := map[string][]string{
459+
"run1": {"Identical output", "Identical output"},
450460
}
461+
451462
expectedPackageOutputs := []string{
452463
"Identical package output",
453464
"Identical package output",
454465
}
455466

456-
if !reflect.DeepEqual(result.Outputs, expectedOutputs) {
457-
t.Errorf("Expected Outputs %v, got %v", expectedOutputs, result.Outputs)
467+
if !reflect.DeepEqual(result.PassedOutputs, expectedOutputs) {
468+
t.Errorf("Expected Outputs %v, got %v", expectedOutputs, result.PassedOutputs)
458469
}
459470

460471
if !reflect.DeepEqual(result.PackageOutputs, expectedPackageOutputs) {
461472
t.Errorf("Expected PackageOutputs %v, got %v", expectedPackageOutputs, result.PackageOutputs)
462473
}
463474
}
464475

465-
// TestMergeTestResults tests the mergeTestResults function.
466-
func TestMergeTestResults(t *testing.T) {
467-
a := TestResult{
468-
TestName: "TestA",
469-
TestPackage: "pkg1",
470-
Runs: 2,
471-
Successes: 2,
472-
Failures: 0,
473-
Skips: 0,
474-
Durations: []time.Duration{time.Second, time.Second},
475-
Outputs: []string{"Output1", "Output2"},
476-
PackageOutputs: []string{"PkgOutput1"},
477-
Panic: false,
478-
Race: false,
479-
Skipped: false,
480-
}
481-
482-
b := TestResult{
483-
TestName: "TestA",
484-
TestPackage: "pkg1",
485-
Runs: 3,
486-
Successes: 2,
487-
Failures: 1,
488-
Skips: 0,
489-
Durations: []time.Duration{2 * time.Second, 2 * time.Second, 2 * time.Second},
490-
Outputs: []string{"Output3", "Output4", "Output5"},
491-
PackageOutputs: []string{"PkgOutput2"},
492-
Panic: true,
493-
Race: false,
494-
Skipped: false,
495-
}
496-
497-
merged := mergeTestResults(a, b)
498-
499-
expected := TestResult{
500-
TestName: "TestA",
501-
TestPackage: "pkg1",
502-
Runs: 5,
503-
Successes: 4,
504-
Failures: 1,
505-
Skips: 0,
506-
Durations: []time.Duration{time.Second, time.Second, 2 * time.Second, 2 * time.Second, 2 * time.Second},
507-
Outputs: []string{"Output1", "Output2", "Output3", "Output4", "Output5"},
508-
PackageOutputs: []string{"PkgOutput1", "PkgOutput2"},
509-
Panic: true,
510-
Race: false,
511-
Skipped: false,
512-
PassRatio: 0.8,
513-
}
514-
515-
if !reflect.DeepEqual(merged, expected) {
516-
t.Errorf("Expected %+v, got %+v", expected, merged)
517-
}
518-
}
519-
520476
// TestAvgDuration tests the avgDuration function.
521477
func TestAvgDuration(t *testing.T) {
522478
durations := []time.Duration{

tools/flakeguard/reports/io.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ func SaveSummaryAsJSON(fs FileSystem, path string, summary SummaryData) error {
216216
func SaveReportNoLogs(fs FileSystem, filePath string, report TestReport) error {
217217
var filteredResults []TestResult
218218
for _, r := range report.Results {
219-
r.Outputs = nil
219+
r.FailedOutputs = nil
220+
r.PassedOutputs = nil
220221
r.PackageOutputs = nil
221222
filteredResults = append(filteredResults, r)
222223
}

0 commit comments

Comments
 (0)