Skip to content

Commit 3e1d9a2

Browse files
committed
Add shuffle option to flakeguard
1 parent 9c9821d commit 3e1d9a2

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

tools/flakeguard/cmd/run.go

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

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

5660
testResults, err := runner.RunTests()
@@ -102,6 +106,8 @@ func init() {
102106
RunTestsCmd.Flags().Bool("run-all-packages", false, "Run all test packages in the project. This flag overrides --test-packages and --test-packages-json")
103107
RunTestsCmd.Flags().IntP("run-count", "c", 1, "Number of times to run the tests")
104108
RunTestsCmd.Flags().Bool("race", false, "Enable the race detector")
109+
RunTestsCmd.Flags().Bool("shuffle", false, "Enable test shuffling")
110+
RunTestsCmd.Flags().String("shuffle-seed", "", "Set seed for test shuffling. Must be used with --shuffle")
105111
RunTestsCmd.Flags().Bool("fail-fast", false, "Stop on the first test failure")
106112
RunTestsCmd.Flags().String("output-json", "", "Path to output the test results in JSON format")
107113
RunTestsCmd.Flags().Float64("threshold", 0.8, "Threshold for considering a test as flaky")

tools/flakeguard/runner/runner.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ type Runner struct {
2323
Verbose bool // If true, provides detailed logging.
2424
RunCount int // Number of times to run the tests.
2525
UseRace bool // Enable race detector.
26+
UseShuffle bool // Enable test shuffling. -shuffle=on flag.
27+
ShuffleSeed string // Set seed for test shuffling -shuffle={seed} flag. Must be used with UseShuffle.
2628
FailFast bool // Stop on first test failure.
2729
SkipTests []string // Test names to exclude.
2830
SelectedTestPackages []string // Explicitly selected packages to run.
@@ -59,6 +61,14 @@ func (r *Runner) runTests(packageName string) (string, bool, error) {
5961
if r.UseRace {
6062
args = append(args, "-race")
6163
}
64+
if r.UseShuffle {
65+
if r.ShuffleSeed != "" {
66+
args = append(args, fmt.Sprintf("-shuffle=%s", r.ShuffleSeed))
67+
} else {
68+
args = append(args, "-shuffle=on")
69+
}
70+
}
71+
6272
if len(r.SkipTests) > 0 {
6373
skipPattern := strings.Join(r.SkipTests, "|")
6474
args = append(args, fmt.Sprintf("-skip=%s", skipPattern))

0 commit comments

Comments
 (0)