Skip to content

Commit 340e10c

Browse files
committed
fix
1 parent 7d65d29 commit 340e10c

File tree

4 files changed

+42
-20
lines changed

4 files changed

+42
-20
lines changed

tools/flakeguard/cmd/generate_report.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ var GenerateReportCmd = &cobra.Command{
3939
s.Suffix = " Loading aggregated test report..."
4040
s.Start()
4141

42-
aggregatedReport := &reports.TestReport{}
42+
aggregatedReport := reports.TestReport{}
4343
reportFile, err := os.Open(aggregatedResultsPath)
4444
if err != nil {
4545
s.Stop()
@@ -166,7 +166,7 @@ func init() {
166166
}
167167
}
168168

169-
func generateGitHubSummaryMarkdown(report *reports.TestReport, outputPath, artifactLink, artifactName string) error {
169+
func generateGitHubSummaryMarkdown(report reports.TestReport, outputPath, artifactLink, artifactName string) error {
170170
fs := reports.OSFileSystem{}
171171
mdFileName := outputPath + "-summary.md"
172172
mdFile, err := fs.Create(mdFileName)
@@ -182,7 +182,7 @@ func generateGitHubSummaryMarkdown(report *reports.TestReport, outputPath, artif
182182
}
183183

184184
func generatePRCommentMarkdown(
185-
report *reports.TestReport,
185+
report reports.TestReport,
186186
outputPath,
187187
baseBranch,
188188
currentBranch,

tools/flakeguard/cmd/run.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,9 @@ var RunTestsCmd = &cobra.Command{
138138
return
139139
}
140140

141-
fmt.Printf("\nFlakeguard Initial Summary:\n")
142-
reports.RenderResults(os.Stdout, mainReport, false, false)
141+
fmt.Printf("\nFlakeguard Main Summary:\n")
142+
reports.RenderResults(os.Stdout, *mainReport, false, false)
143+
fmt.Println()
143144

144145
// Rerun failed tests
145146
if rerunFailed > 0 {
@@ -154,15 +155,16 @@ var RunTestsCmd = &cobra.Command{
154155
return !tr.Skipped && tr.Successes == 0
155156
})
156157
fmt.Printf("\nFlakeguard Rerun Summary:\n")
157-
reports.RenderResults(os.Stdout, rerunReport, false, false)
158+
reports.PrintTestTable(os.Stdout, *rerunReport, false, false)
159+
fmt.Println()
158160

159161
// Save the rerun test report to file
160-
if rerunReportPath != "" && len(mainReport.Results) > 0 {
162+
if rerunReportPath != "" && len(rerunReport.Results) > 0 {
161163
if err := rerunReport.SaveToFile(rerunReportPath); err != nil {
162164
log.Error().Err(err).Msg("Error saving test results to file")
163165
os.Exit(ErrorExitCode)
164166
}
165-
log.Info().Str("path", rerunReportPath).Msg("Main test report saved")
167+
log.Info().Str("path", rerunReportPath).Msg("Rerun test report saved")
166168
}
167169

168170
if len(failedAfterRerun) > 0 {
@@ -172,7 +174,7 @@ var RunTestsCmd = &cobra.Command{
172174
Msg("Tests still failing after reruns with 0 successes")
173175
os.Exit(ErrorExitCode)
174176
} else {
175-
log.Info().Msg("Failed tests passed at least once after reruns")
177+
log.Info().Msg("Tests that failed passed at least once after reruns")
176178
os.Exit(0)
177179
}
178180
} else {

tools/flakeguard/reports/presentation.go

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ import (
1010
"golang.org/x/text/message"
1111
)
1212

13-
// GenerateFlakyTestsTable generates a table of flaky tests from the given test report to print to the console or markdown.
14-
func GenerateFlakyTestsTable(
15-
testReport *TestReport,
13+
// generateTestTable is a helper that builds the table based on the given filter function.
14+
func generateTestTable(
15+
testReport TestReport,
1616
markdown bool,
17+
filter func(result TestResult) bool,
1718
) [][]string {
1819
p := message.NewPrinter(language.English)
1920

@@ -45,8 +46,7 @@ func GenerateFlakyTestsTable(
4546
table := [][]string{headers}
4647

4748
for _, result := range testReport.Results {
48-
// Exclude skipped tests and only include tests below the expected pass ratio
49-
if !result.Skipped && result.PassRatio < testReport.MaxPassRatio {
49+
if filter(result) {
5050
row := []string{
5151
result.TestName,
5252
formatRatio(result.PassRatio),
@@ -75,8 +75,30 @@ func GenerateFlakyTestsTable(
7575
return table
7676
}
7777

78+
// GenerateFlakyTestsTable returns a table with only the flaky tests.
79+
func GenerateFlakyTestsTable(
80+
testReport TestReport,
81+
markdown bool,
82+
) [][]string {
83+
return generateTestTable(testReport, markdown, func(result TestResult) bool {
84+
return !result.Skipped && result.PassRatio < testReport.MaxPassRatio
85+
})
86+
}
87+
88+
// PrintTestTable prints a table with all test results.
89+
func PrintTestTable(
90+
w io.Writer,
91+
testReport TestReport,
92+
markdown bool,
93+
collapsible bool) {
94+
table := generateTestTable(testReport, markdown, func(result TestResult) bool {
95+
return true // Include all tests
96+
})
97+
printTable(w, table, collapsible)
98+
}
99+
78100
// GenerateGitHubSummaryMarkdown generates a markdown summary of the test results for a GitHub workflow summary
79-
func GenerateGitHubSummaryMarkdown(w io.Writer, testReport *TestReport, maxPassRatio float64, artifactName, artifactLink string) {
101+
func GenerateGitHubSummaryMarkdown(w io.Writer, testReport TestReport, maxPassRatio float64, artifactName, artifactLink string) {
80102
fmt.Fprint(w, "# Flakeguard Summary\n\n")
81103

82104
if len(testReport.Results) == 0 {
@@ -109,7 +131,7 @@ func GenerateGitHubSummaryMarkdown(w io.Writer, testReport *TestReport, maxPassR
109131
// GeneratePRCommentMarkdown generates a markdown summary of the test results for a GitHub PR comment.
110132
func GeneratePRCommentMarkdown(
111133
w io.Writer,
112-
testReport *TestReport,
134+
testReport TestReport,
113135
maxPassRatio float64,
114136
baseBranch, currentBranch, currentCommitSHA, repoURL, actionRunID, artifactName, artifactLink string,
115137
) {
@@ -156,7 +178,7 @@ func GeneratePRCommentMarkdown(
156178
}
157179
}
158180

159-
func buildSettingsTable(testReport *TestReport, maxPassRatio float64) [][]string {
181+
func buildSettingsTable(testReport TestReport, maxPassRatio float64) [][]string {
160182
rows := [][]string{
161183
{"**Setting**", "**Value**"},
162184
}
@@ -190,7 +212,7 @@ func RenderError(
190212
// If in markdown mode, the table results can also be made collapsible.
191213
func RenderResults(
192214
w io.Writer,
193-
testReport *TestReport,
215+
testReport TestReport,
194216
markdown bool,
195217
collapsible bool,
196218
) {

tools/flakeguard/runner/example_test_package/example_tests_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,6 @@ func TestTimeout(t *testing.T) {
218218
func TestRandomFlaky(t *testing.T) {
219219
t.Parallel()
220220

221-
time.Sleep(100 * time.Millisecond)
222-
223221
// Seed random number generator with current time
224222
seed := time.Now().UnixNano()
225223
t.Logf("Using seed: %d", seed)

0 commit comments

Comments
 (0)