Skip to content

Commit 989ea05

Browse files
committed
Update go-test-timeout flag to test runner and update Runner struct
1 parent db384f4 commit 989ea05

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed

tools/flakeguard/cmd/run.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ var RunTestsCmd = &cobra.Command{
4040
testCmdStrings, _ := cmd.Flags().GetStringArray("test-cmd")
4141
runCount, _ := cmd.Flags().GetInt("run-count")
4242
rerunFailedCount, _ := cmd.Flags().GetInt("rerun-failed-count")
43-
timeout, _ := cmd.Flags().GetDuration("timeout")
4443
tags, _ := cmd.Flags().GetStringArray("tags")
4544
useRace, _ := cmd.Flags().GetBool("race")
4645
mainReportPath, _ := cmd.Flags().GetString("main-report-path")
@@ -56,16 +55,17 @@ var RunTestsCmd = &cobra.Command{
5655
omitOutputsOnSuccess, _ := cmd.Flags().GetBool("omit-test-outputs-on-success")
5756
ignoreParentFailuresOnSubtests, _ := cmd.Flags().GetBool("ignore-parent-failures-on-subtests")
5857
failFast, _ := cmd.Flags().GetBool("fail-fast")
58+
goTestTimeoutFlag, _ := cmd.Flags().GetString("go-test-timeout")
5959

6060
// Retrieve go-test-count flag as a pointer if explicitly provided.
61-
var goTestCount *int
61+
var goTestCountFlag *int
6262
if cmd.Flags().Changed("go-test-count") {
6363
v, err := cmd.Flags().GetInt("go-test-count")
6464
if err != nil {
6565
log.Error().Err(err).Msg("Error retrieving flag go-test-count")
6666
flushSummaryAndExit(ErrorExitCode)
6767
}
68-
goTestCount = &v
68+
goTestCountFlag = &v
6969
}
7070

7171
// Handle the compatibility between min/max pass ratio
@@ -109,9 +109,9 @@ var RunTestsCmd = &cobra.Command{
109109
ProjectPath: projectPath,
110110
Verbose: true,
111111
RunCount: runCount,
112-
Timeout: timeout,
112+
GoTestTimeoutFlag: goTestTimeoutFlag,
113113
Tags: tags,
114-
GoTestCountFlag: goTestCount,
114+
GoTestCountFlag: goTestCountFlag,
115115
GoTestRaceFlag: useRace,
116116
SkipTests: skipTests,
117117
SelectTests: selectTests,
@@ -253,8 +253,8 @@ func init() {
253253
)
254254
RunTestsCmd.Flags().Bool("run-all-packages", false, "Run all test packages in the project. This flag overrides --test-packages and --test-packages-json")
255255
RunTestsCmd.Flags().IntP("run-count", "c", 1, "Number of times to run the tests")
256-
RunTestsCmd.Flags().Duration("timeout", 0, "Passed on to the 'go test' command as the -timeout flag")
257256
RunTestsCmd.Flags().StringArray("tags", nil, "Passed on to the 'go test' command as the -tags flag")
257+
RunTestsCmd.Flags().String("go-test-timeout", "", "Passed on to the 'go test' command as the -timeout flag")
258258
RunTestsCmd.Flags().Int("go-test-count", -1, "go test -count flag value. By default -count flag is not passed to go test")
259259
RunTestsCmd.Flags().Bool("race", false, "Enable the race detector")
260260
RunTestsCmd.Flags().Bool("shuffle", false, "Enable test shuffling")

tools/flakeguard/runner/runner.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,24 @@ var (
2727

2828
// Runner describes the test run parameters and raw test outputs
2929
type Runner struct {
30-
ProjectPath string // Path to the Go project directory.
31-
prettyProjectPath string // Go project package path, formatted for pretty printing.
32-
Verbose bool // If true, provides detailed logging.
33-
RunCount int // Number of times to run the tests.
34-
RerunCount int // Number of additional runs for tests that initially fail.
35-
GoTestCountFlag *int // Run go test with -count flag.
36-
GoTestRaceFlag bool // Run go test with -race flag.
37-
Timeout time.Duration // Test timeout
38-
Tags []string // Build tags.
39-
UseShuffle bool // Enable test shuffling. -shuffle=on flag.
40-
ShuffleSeed string // Set seed for test shuffling -shuffle={seed} flag. Must be used with UseShuffle.
41-
FailFast bool // Stop on first test failure.
42-
SkipTests []string // Test names to exclude.
43-
SelectTests []string // Test names to include.
44-
CollectRawOutput bool // Set to true to collect test output for later inspection.
45-
OmitOutputsOnSuccess bool // Set to true to omit test outputs on success.
46-
MaxPassRatio float64 // Maximum pass ratio threshold for a test to be considered flaky.
47-
IgnoreParentFailuresOnSubtests bool // Ignore failures in parent tests when only subtests fail.
30+
ProjectPath string // Path to the Go project directory.
31+
prettyProjectPath string // Go project package path, formatted for pretty printing.
32+
Verbose bool // If true, provides detailed logging.
33+
RunCount int // Number of times to run the tests.
34+
RerunCount int // Number of additional runs for tests that initially fail.
35+
GoTestCountFlag *int // Run go test with -count flag.
36+
GoTestRaceFlag bool // Run go test with -race flag.
37+
GoTestTimeoutFlag string // Run go test with -timeout flag
38+
Tags []string // Build tags.
39+
UseShuffle bool // Enable test shuffling. -shuffle=on flag.
40+
ShuffleSeed string // Set seed for test shuffling -shuffle={seed} flag. Must be used with UseShuffle.
41+
FailFast bool // Stop on first test failure.
42+
SkipTests []string // Test names to exclude.
43+
SelectTests []string // Test names to include.
44+
CollectRawOutput bool // Set to true to collect test output for later inspection.
45+
OmitOutputsOnSuccess bool // Set to true to omit test outputs on success.
46+
MaxPassRatio float64 // Maximum pass ratio threshold for a test to be considered flaky.
47+
IgnoreParentFailuresOnSubtests bool // Ignore failures in parent tests when only subtests fail.
4848
rawOutputs map[string]*bytes.Buffer
4949
}
5050

@@ -151,8 +151,8 @@ func (r *Runner) runTestPackage(packageName string) (string, bool, error) {
151151
if r.GoTestRaceFlag {
152152
args = append(args, "-race")
153153
}
154-
if r.Timeout > 0 {
155-
args = append(args, fmt.Sprintf("-timeout=%s", r.Timeout.String()))
154+
if r.GoTestTimeoutFlag != "" {
155+
args = append(args, fmt.Sprintf("-timeout=%s", r.GoTestTimeoutFlag))
156156
}
157157
if len(r.Tags) > 0 {
158158
args = append(args, fmt.Sprintf("-tags=%s", strings.Join(r.Tags, ",")))
@@ -755,8 +755,8 @@ func (r *Runner) RerunFailedTests(failedTests []reports.TestResult) (*reports.Te
755755
if r.GoTestRaceFlag {
756756
cmd = append(cmd, "-race")
757757
}
758-
if r.Timeout > 0 {
759-
cmd = append(cmd, fmt.Sprintf("-timeout=%s", r.Timeout.String()))
758+
if r.GoTestTimeoutFlag != "" {
759+
cmd = append(cmd, fmt.Sprintf("-timeout=%s", r.GoTestTimeoutFlag))
760760
}
761761
if len(r.Tags) > 0 {
762762
cmd = append(cmd, fmt.Sprintf("-tags=%s", strings.Join(r.Tags, ",")))

0 commit comments

Comments
 (0)