Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev: override bazel timeout when run under stress #72046

Merged
merged 1 commit into from
Oct 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions pkg/cmd/dev/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func makeTestCmd(runE func(cmd *cobra.Command, args []string) error) *cobra.Comm
addCommonTestFlags(testCmd)
testCmd.Flags().BoolP(vFlag, "v", false, "enable logging during test runs")
testCmd.Flags().Bool(stressFlag, false, "run tests under stress")
testCmd.Flags().String(stressArgsFlag, "", "Additional arguments to pass to stress")
testCmd.Flags().String(stressArgsFlag, "", "additional arguments to pass to stress")
testCmd.Flags().Bool(raceFlag, false, "run tests using race builds")
testCmd.Flags().Bool(ignoreCacheFlag, false, "ignore cached test runs")
testCmd.Flags().String(rewriteFlag, "", "argument to pass to underlying (only applicable for certain tests, e.g. logic and datadriven tests). If unspecified, -rewrite will be passed to the test binary.")
Expand Down Expand Up @@ -83,9 +83,6 @@ func (d *dev) test(cmd *cobra.Command, commandLine []string) error {
rewrite = "-rewrite"
}

d.log.Printf("unit test args: stress=%t race=%t filter=%s timeout=%s ignore-cache=%t pkgs=%s",
stress, race, filter, timeout, ignoreCache, pkgs)

var args []string
args = append(args, "test")
args = append(args, mustGetRemoteCacheArgs(remoteCacheAddr)...)
Expand Down Expand Up @@ -178,17 +175,29 @@ func (d *dev) test(cmd *cobra.Command, commandLine []string) error {
args = append(args, fmt.Sprintf("--sandbox_writable_path=%s", filepath.Join(workspace, dir)))
}
}
if stress && timeout > 0 {
args = append(args, "--run_under", fmt.Sprintf("%s -maxtime=%s %s", stressTarget, timeout, stressArgs))
// The timeout should be a bit higher than the stress duration.
// Bazel will probably think the timeout for this test isn't so
// long.
args = append(args, fmt.Sprintf("--test_timeout=%d", int((timeout+1*time.Second).Seconds())))
} else if stress {
args = append(args, "--run_under", fmt.Sprintf("%s %s", stressTarget, stressArgs))
if stress {
if timeout > 0 {
args = append(args, "--run_under",
fmt.Sprintf("%s -maxtime=%s %s", stressTarget, timeout, stressArgs))

// The bazel timeout needs to be higher than the stress duration to
// pass reliably.
args = append(args, fmt.Sprintf("--test_timeout=%.0f", (timeout+time.Second).Seconds()))
} else {
// We're running under stress and no timeout is specified. We want
// to respect the timeout passed down to stress[1]. Similar to above
// we want the bazel timeout to be longer, so lets just set it to
// 24h.
//
// [1]: Through --stress-arg=-maxtime or if nothing is specified, a
// -maxtime of 0 that's taken as "run forever")
args = append(args, "--run_under", fmt.Sprintf("%s %s", stressTarget, stressArgs))
args = append(args, fmt.Sprintf("--test_timeout=%.0f", 24*time.Hour.Seconds()))
}
} else if timeout > 0 {
args = append(args, fmt.Sprintf("--test_timeout=%d", int(timeout.Seconds())))
}

if filter != "" {
args = append(args, fmt.Sprintf("--test_filter=%s", filter))
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/dev/testdata/recording/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ bazel query 'kind(go_test, //pkg/util/tracing:all)'
----
//pkg/util/tracing:tracing_test

bazel test --test_sharding_strategy=disabled //pkg/util/tracing:tracing_test --run_under '@com_github_cockroachdb_stress//:stress ' '--test_filter=TestStartChild*' --test_output streamed
bazel test --test_sharding_strategy=disabled //pkg/util/tracing:tracing_test --run_under '@com_github_cockroachdb_stress//:stress ' --test_timeout=86400 '--test_filter=TestStartChild*' --test_output streamed
----
----
//pkg/util/tracing:tracing_test PASSED in 12.3s
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/dev/testdata/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ bazel test //pkg/util/tracing:tracing_test --nocache_test_results '--test_filter
dev test --stress pkg/util/tracing --filter TestStartChild*
----
bazel query 'kind(go_test, //pkg/util/tracing:all)'
bazel test --test_sharding_strategy=disabled //pkg/util/tracing:tracing_test --run_under '@com_github_cockroachdb_stress//:stress ' '--test_filter=TestStartChild*' --test_output streamed
bazel test --test_sharding_strategy=disabled //pkg/util/tracing:tracing_test --run_under '@com_github_cockroachdb_stress//:stress ' --test_timeout=86400 '--test_filter=TestStartChild*' --test_output streamed

dev test --stress pkg/util/tracing --filter TestStartChild* --timeout=10s -v
----
Expand Down