Skip to content

Commit a189df7

Browse files
committed
roachtest: remove global-seed flag
This flag allows the user to seed the global rng instance for the entire test suite run. This flag is rarely (never) used and adds confusion for test writers as they are unsure if they should use the global seed or the test scoped COCKROACH_RANDOM_SEED. This changes the flag to be a ROACHTEST_GLOBAL_SEED env var which still allows it to be set, but unexposes it from being used directly in roachtests themselves.
1 parent 7167c08 commit a189df7

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

pkg/cmd/roachtest/roachtestflags/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ go_library(
1111
deps = [
1212
"//pkg/cmd/roachtest/spec",
1313
"//pkg/roachprod/vm",
14-
"//pkg/util/randutil",
1514
"@com_github_cockroachdb_errors//:errors",
1615
"@com_github_spf13_pflag//:pflag",
1716
],

pkg/cmd/roachtest/roachtestflags/flags.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212

1313
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/spec"
1414
"github.com/cockroachdb/cockroach/pkg/roachprod/vm"
15-
"github.com/cockroachdb/cockroach/pkg/util/randutil"
1615
"github.com/spf13/pflag"
1716
)
1817

@@ -476,12 +475,6 @@ var (
476475
Usage: `Percentage of failed tests before all remaining tests are automatically terminated.`,
477476
})
478477

479-
GlobalSeed int64 = randutil.NewPseudoSeed()
480-
_ = registerRunFlag(&GlobalSeed, FlagInfo{
481-
Name: "global-seed",
482-
Usage: `The global random seed used for all tests.`,
483-
})
484-
485478
ClearClusterCache bool = true
486479
_ = registerRunFlag(&ClearClusterCache, FlagInfo{
487480
Name: "clear-cluster-cache",

pkg/cmd/roachtest/run.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"os/user"
1616
"path/filepath"
1717
"runtime"
18+
"strconv"
1819
"strings"
1920
"time"
2021

@@ -30,6 +31,7 @@ import (
3031
"github.com/cockroachdb/cockroach/pkg/roachprod/logger"
3132
"github.com/cockroachdb/cockroach/pkg/util/allstacks"
3233
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
34+
"github.com/cockroachdb/cockroach/pkg/util/randutil"
3335
"github.com/cockroachdb/cockroach/pkg/util/stop"
3436
"github.com/cockroachdb/cockroach/pkg/util/timeutil"
3537
"github.com/cockroachdb/errors"
@@ -50,8 +52,16 @@ const (
5052
// runTests is the main function for the run and bench commands.
5153
// Assumes initRunFlagsBinariesAndLibraries was called.
5254
func runTests(register func(registry.Registry), filter *registry.TestFilter) error {
55+
globalSeed := randutil.NewPseudoSeed()
56+
if globalSeedEnv := os.Getenv("ROACHTEST_GLOBAL_SEED"); globalSeedEnv != "" {
57+
if parsed, err := strconv.ParseInt(globalSeedEnv, 0, 64); err == nil {
58+
globalSeed = parsed
59+
} else {
60+
return errors.Wrapf(err, "could not parse ROACHTEST_GLOBAL_SEED=%q", globalSeedEnv)
61+
}
62+
}
5363
//lint:ignore SA1019 deprecated
54-
rand.Seed(roachtestflags.GlobalSeed)
64+
rand.Seed(globalSeed)
5565
r := makeTestRegistry()
5666

5767
// actual registering of tests
@@ -147,7 +157,7 @@ func runTests(register func(registry.Registry), filter *registry.TestFilter) err
147157
teamLoader: team.DefaultLoadTeams,
148158
}
149159

150-
l.Printf("global random seed: %d", roachtestflags.GlobalSeed)
160+
l.Printf("global random seed: %d", globalSeed)
151161
go func() {
152162
if err := http.ListenAndServe(
153163
fmt.Sprintf(":%d", roachtestflags.PromPort),

0 commit comments

Comments
 (0)