Skip to content

Commit 79a639b

Browse files
committed
Do not try to rerun tests if all passed
1 parent 9128578 commit 79a639b

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

tools/flakeguard/cmd/run.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,16 @@ var RunTestsCmd = &cobra.Command{
144144

145145
// Rerun failed tests
146146
if rerunFailedCount > 0 {
147-
rerunReport, err = testRunner.RerunFailedTests(mainReport.Results)
147+
failedTests := reports.FilterTests(mainReport.Results, func(tr reports.TestResult) bool {
148+
return !tr.Skipped && tr.PassRatio < 1.0
149+
})
150+
151+
if len(failedTests) == 0 {
152+
log.Info().Msg("No tests to rerun. All tests passed")
153+
os.Exit(0)
154+
}
155+
156+
rerunReport, err = testRunner.RerunFailedTests(failedTests)
148157
if err != nil {
149158
log.Fatal().Err(err).Msg("Error rerunning failed tests")
150159
os.Exit(ErrorExitCode)
@@ -227,7 +236,7 @@ func init() {
227236
RunTestsCmd.Flags().Bool("ignore-parent-failures-on-subtests", false, "Ignore failures in parent tests when only subtests fail")
228237

229238
// Add rerun failed tests flag
230-
RunTestsCmd.Flags().Int("rerun-failed-count", 0, "Number of times to rerun failed tests (0 disables reruns)")
239+
RunTestsCmd.Flags().Int("rerun-failed-count", 0, "Number of times to rerun tests that did not get 100 percent pass ratio (0 disables reruns)")
231240
}
232241

233242
func checkDependencies(projectPath string) error {

tools/flakeguard/runner/runner.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -720,17 +720,11 @@ func prettyProjectPath(projectPath string) (string, error) {
720720
return "", fmt.Errorf("module path not found in go.mod")
721721
}
722722

723-
func (r *Runner) RerunFailedTests(results []reports.TestResult) (*reports.TestReport, error) {
724-
// Group failing tests by package for more efficient reruns
723+
func (r *Runner) RerunFailedTests(failedTests []reports.TestResult) (*reports.TestReport, error) {
724+
// Group the provided failed tests by package for more efficient reruns
725725
failingTestsByPackage := make(map[string][]string)
726-
for _, tr := range results {
727-
if !tr.Skipped {
728-
// if !tr.Skipped && tr.PassRatio < 1 { //TODO uncomment
729-
if _, exists := failingTestsByPackage[tr.TestPackage]; !exists {
730-
failingTestsByPackage[tr.TestPackage] = []string{}
731-
}
732-
failingTestsByPackage[tr.TestPackage] = append(failingTestsByPackage[tr.TestPackage], tr.TestName)
733-
}
726+
for _, tr := range failedTests {
727+
failingTestsByPackage[tr.TestPackage] = append(failingTestsByPackage[tr.TestPackage], tr.TestName)
734728
}
735729

736730
if r.Verbose {
@@ -739,7 +733,7 @@ func (r *Runner) RerunFailedTests(results []reports.TestResult) (*reports.TestRe
739733

740734
var rerunJsonFilePaths []string
741735

742-
// Rerun each failing test package up to RerunFailed times
736+
// Rerun each failing test package up to RerunCount times
743737
for i := range r.RerunCount {
744738
for pkg, tests := range failingTestsByPackage {
745739
// Build regex pattern to match all failing tests in this package
@@ -773,7 +767,6 @@ func (r *Runner) RerunFailedTests(results []reports.TestResult) (*reports.TestRe
773767
if err != nil {
774768
return nil, fmt.Errorf("error on rerunCmd for package %s: %w", pkg, err)
775769
}
776-
777770
rerunJsonFilePaths = append(rerunJsonFilePaths, jsonFilePath)
778771
}
779772
}

0 commit comments

Comments
 (0)