Skip to content

Commit

Permalink
Add shuffle option to flakeguard (#1379)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszcl authored Nov 25, 2024
1 parent a5d48c9 commit 18318aa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tools/flakeguard/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ var RunTestsCmd = &cobra.Command{
maxPassRatio, _ := cmd.Flags().GetFloat64("max-pass-ratio")
skipTests, _ := cmd.Flags().GetStringSlice("skip-tests")
printFailedTests, _ := cmd.Flags().GetBool("print-failed-tests")
useShuffle, _ := cmd.Flags().GetBool("shuffle")
shuffleSeed, _ := cmd.Flags().GetString("shuffle-seed")

// Check if project dependencies are correctly set up
if err := checkDependencies(projectPath); err != nil {
Expand All @@ -50,6 +52,8 @@ var RunTestsCmd = &cobra.Command{
UseRace: useRace,
SkipTests: skipTests,
SelectedTestPackages: testPackages,
UseShuffle: useShuffle,
ShuffleSeed: shuffleSeed,
}

testResults, err := runner.RunTests()
Expand Down Expand Up @@ -101,6 +105,8 @@ func init() {
RunTestsCmd.Flags().Bool("run-all-packages", false, "Run all test packages in the project. This flag overrides --test-packages and --test-packages-json")
RunTestsCmd.Flags().IntP("run-count", "c", 1, "Number of times to run the tests")
RunTestsCmd.Flags().Bool("race", false, "Enable the race detector")
RunTestsCmd.Flags().Bool("shuffle", false, "Enable test shuffling")
RunTestsCmd.Flags().String("shuffle-seed", "", "Set seed for test shuffling. Must be used with --shuffle")
RunTestsCmd.Flags().Bool("fail-fast", false, "Stop on the first test failure")
RunTestsCmd.Flags().String("output-json", "", "Path to output the test results in JSON format")
RunTestsCmd.Flags().StringSlice("skip-tests", nil, "Comma-separated list of test names to skip from running")
Expand Down
9 changes: 9 additions & 0 deletions tools/flakeguard/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ type Runner struct {
Verbose bool // If true, provides detailed logging.
RunCount int // Number of times to run the tests.
UseRace bool // Enable race detector.
UseShuffle bool // Enable test shuffling. -shuffle=on flag.
ShuffleSeed string // Set seed for test shuffling -shuffle={seed} flag. Must be used with UseShuffle.
FailFast bool // Stop on first test failure.
SkipTests []string // Test names to exclude.
SelectedTestPackages []string // Explicitly selected packages to run.
Expand Down Expand Up @@ -93,6 +95,13 @@ func (r *Runner) runTests(packageName string) (string, bool, error) {
if r.UseRace {
args = append(args, "-race")
}
if r.UseShuffle {
if r.ShuffleSeed != "" {
args = append(args, fmt.Sprintf("-shuffle=%s", r.ShuffleSeed))
} else {
args = append(args, "-shuffle=on")
}
}
if len(r.SkipTests) > 0 {
skipPattern := strings.Join(r.SkipTests, "|")
args = append(args, fmt.Sprintf("-skip=%s", skipPattern))
Expand Down

0 comments on commit 18318aa

Please sign in to comment.