Skip to content

Commit 2a8e6cd

Browse files
authored
flakeguard: Add option to skip running some tests (#1286)
1 parent 0f4e9bd commit 2a8e6cd

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

tools/flakeguard/cmd/run.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ var RunTestsCmd = &cobra.Command{
2222
useRace, _ := cmd.Flags().GetBool("race")
2323
outputPath, _ := cmd.Flags().GetString("output-json")
2424
threshold, _ := cmd.Flags().GetFloat64("threshold")
25+
skipTests, _ := cmd.Flags().GetStringSlice("skip-tests")
2526

2627
var testPackages []string
2728
if testPackagesJson != "" {
@@ -40,6 +41,7 @@ var RunTestsCmd = &cobra.Command{
4041
RunCount: runCount,
4142
UseRace: useRace,
4243
FailFast: threshold == 1.0, // Fail test on first test run if threshold is 1.0
44+
SkipTests: skipTests,
4345
}
4446

4547
testResults, err := runner.RunTests(testPackages)
@@ -84,12 +86,13 @@ var RunTestsCmd = &cobra.Command{
8486
}
8587

8688
func init() {
87-
RunTestsCmd.Flags().StringP("project-path", "r", ".", "The path to the Go project. Default is the current directory. Useful for subprojects.")
89+
RunTestsCmd.Flags().StringP("project-path", "r", ".", "The path to the Go project. Default is the current directory. Useful for subprojects")
8890
RunTestsCmd.Flags().String("test-packages-json", "", "JSON-encoded string of test packages")
8991
RunTestsCmd.Flags().StringSlice("test-packages", nil, "Comma-separated list of test packages to run")
9092
RunTestsCmd.Flags().IntP("run-count", "c", 1, "Number of times to run the tests")
9193
RunTestsCmd.Flags().Bool("race", false, "Enable the race detector")
9294
RunTestsCmd.Flags().Bool("fail-fast", false, "Stop on the first test failure")
9395
RunTestsCmd.Flags().String("output-json", "", "Path to output the test results in JSON format")
9496
RunTestsCmd.Flags().Float64("threshold", 0.8, "Threshold for considering a test as flaky")
97+
RunTestsCmd.Flags().StringSlice("skip-tests", nil, "Comma-separated list of test names to skip from running")
9598
}

tools/flakeguard/runner/runner.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ import (
1414
)
1515

1616
type Runner struct {
17-
ProjectPath string // Path to the Go project directory.
18-
Verbose bool // If true, provides detailed logging.
19-
RunCount int // Number of times to run the tests.
20-
UseRace bool // Enable race detector.
21-
FailFast bool // Stop on first test failure.
17+
ProjectPath string // Path to the Go project directory.
18+
Verbose bool // If true, provides detailed logging.
19+
RunCount int // Number of times to run the tests.
20+
UseRace bool // Enable race detector.
21+
FailFast bool // Stop on first test failure.
22+
SkipTests []string // Test names to exclude.
2223
}
2324

2425
// RunTests executes the tests for each provided package and aggregates all results.
@@ -53,6 +54,13 @@ func (r *Runner) runTestPackage(testPackage string) ([]byte, bool, error) {
5354
if r.UseRace {
5455
args = append(args, "-race")
5556
}
57+
58+
// Construct regex pattern from ExcludedTests slice
59+
if len(r.SkipTests) > 0 {
60+
skipPattern := strings.Join(r.SkipTests, "|")
61+
args = append(args, fmt.Sprintf("-skip=%s", skipPattern))
62+
}
63+
5664
args = append(args, testPackage)
5765

5866
if r.Verbose {
@@ -61,7 +69,6 @@ func (r *Runner) runTestPackage(testPackage string) ([]byte, bool, error) {
6169
cmd := exec.Command("go", args...)
6270
cmd.Dir = r.ProjectPath
6371

64-
// cmd.Env = append(cmd.Env, "GOFLAGS=-extldflags=-Wl,-ld_classic") // Ensure modules are enabled
6572
var out bytes.Buffer
6673
cmd.Stdout = &out
6774
cmd.Stderr = &out

0 commit comments

Comments
 (0)