Skip to content

Commit

Permalink
Merge branch 'main' into v2-more-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
skudasov committed Oct 31, 2024
2 parents 21c0f3b + 2a8e6cd commit 6ba6b50
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
5 changes: 4 additions & 1 deletion tools/flakeguard/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var RunTestsCmd = &cobra.Command{
useRace, _ := cmd.Flags().GetBool("race")
outputPath, _ := cmd.Flags().GetString("output-json")
threshold, _ := cmd.Flags().GetFloat64("threshold")
skipTests, _ := cmd.Flags().GetStringSlice("skip-tests")

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

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

func init() {
RunTestsCmd.Flags().StringP("project-path", "r", ".", "The path to the Go project. Default is the current directory. Useful for subprojects.")
RunTestsCmd.Flags().StringP("project-path", "r", ".", "The path to the Go project. Default is the current directory. Useful for subprojects")
RunTestsCmd.Flags().String("test-packages-json", "", "JSON-encoded string of test packages")
RunTestsCmd.Flags().StringSlice("test-packages", nil, "Comma-separated list of test packages to run")
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("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().Float64("threshold", 0.8, "Threshold for considering a test as flaky")
RunTestsCmd.Flags().StringSlice("skip-tests", nil, "Comma-separated list of test names to skip from running")
}
19 changes: 13 additions & 6 deletions tools/flakeguard/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ import (
)

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

// RunTests executes the tests for each provided package and aggregates all results.
Expand Down Expand Up @@ -53,6 +54,13 @@ func (r *Runner) runTestPackage(testPackage string) ([]byte, bool, error) {
if r.UseRace {
args = append(args, "-race")
}

// Construct regex pattern from ExcludedTests slice
if len(r.SkipTests) > 0 {
skipPattern := strings.Join(r.SkipTests, "|")
args = append(args, fmt.Sprintf("-skip=%s", skipPattern))
}

args = append(args, testPackage)

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

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

0 comments on commit 6ba6b50

Please sign in to comment.