Skip to content

Commit 18318aa

Browse files
authored
Add shuffle option to flakeguard (#1379)
1 parent a5d48c9 commit 18318aa

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

tools/flakeguard/cmd/run.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ var RunTestsCmd = &cobra.Command{
2626
maxPassRatio, _ := cmd.Flags().GetFloat64("max-pass-ratio")
2727
skipTests, _ := cmd.Flags().GetStringSlice("skip-tests")
2828
printFailedTests, _ := cmd.Flags().GetBool("print-failed-tests")
29+
useShuffle, _ := cmd.Flags().GetBool("shuffle")
30+
shuffleSeed, _ := cmd.Flags().GetString("shuffle-seed")
2931

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

5559
testResults, err := runner.RunTests()
@@ -101,6 +105,8 @@ func init() {
101105
RunTestsCmd.Flags().Bool("run-all-packages", false, "Run all test packages in the project. This flag overrides --test-packages and --test-packages-json")
102106
RunTestsCmd.Flags().IntP("run-count", "c", 1, "Number of times to run the tests")
103107
RunTestsCmd.Flags().Bool("race", false, "Enable the race detector")
108+
RunTestsCmd.Flags().Bool("shuffle", false, "Enable test shuffling")
109+
RunTestsCmd.Flags().String("shuffle-seed", "", "Set seed for test shuffling. Must be used with --shuffle")
104110
RunTestsCmd.Flags().Bool("fail-fast", false, "Stop on the first test failure")
105111
RunTestsCmd.Flags().String("output-json", "", "Path to output the test results in JSON format")
106112
RunTestsCmd.Flags().StringSlice("skip-tests", nil, "Comma-separated list of test names to skip from running")

tools/flakeguard/runner/runner.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ type Runner struct {
2929
Verbose bool // If true, provides detailed logging.
3030
RunCount int // Number of times to run the tests.
3131
UseRace bool // Enable race detector.
32+
UseShuffle bool // Enable test shuffling. -shuffle=on flag.
33+
ShuffleSeed string // Set seed for test shuffling -shuffle={seed} flag. Must be used with UseShuffle.
3234
FailFast bool // Stop on first test failure.
3335
SkipTests []string // Test names to exclude.
3436
SelectedTestPackages []string // Explicitly selected packages to run.
@@ -93,6 +95,13 @@ func (r *Runner) runTests(packageName string) (string, bool, error) {
9395
if r.UseRace {
9496
args = append(args, "-race")
9597
}
98+
if r.UseShuffle {
99+
if r.ShuffleSeed != "" {
100+
args = append(args, fmt.Sprintf("-shuffle=%s", r.ShuffleSeed))
101+
} else {
102+
args = append(args, "-shuffle=on")
103+
}
104+
}
96105
if len(r.SkipTests) > 0 {
97106
skipPattern := strings.Join(r.SkipTests, "|")
98107
args = append(args, fmt.Sprintf("-skip=%s", skipPattern))

0 commit comments

Comments
 (0)