Skip to content

Commit 654a5bf

Browse files
craig[bot]pav-kv
andcommitted
Merge #157995
157995: testcluster: reduce ClusterName collisions r=stevendanna,srosenberg a=pav-kv As suggested in #157868 (comment), `rand.Uint32()` has a pretty high chance of collision. This PR increases the space from `2^32` to `62^10`. Addresses #157838 Co-authored-by: Pavel Kalinnikov <[email protected]>
2 parents a325c69 + f9b9af8 commit 654a5bf

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

pkg/testutils/testcluster/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ go_library(
3838
"//pkg/util/allstacks",
3939
"//pkg/util/hlc",
4040
"//pkg/util/log",
41+
"//pkg/util/randutil",
4142
"//pkg/util/retry",
4243
"//pkg/util/stop",
4344
"//pkg/util/syncutil",

pkg/testutils/testcluster/testcluster.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"context"
1010
gosql "database/sql"
1111
"fmt"
12-
"math/rand/v2"
12+
"math/rand"
1313
"net"
1414
"os"
1515
"reflect"
@@ -51,6 +51,7 @@ import (
5151
"github.com/cockroachdb/cockroach/pkg/util/allstacks"
5252
"github.com/cockroachdb/cockroach/pkg/util/hlc"
5353
"github.com/cockroachdb/cockroach/pkg/util/log"
54+
"github.com/cockroachdb/cockroach/pkg/util/randutil"
5455
"github.com/cockroachdb/cockroach/pkg/util/retry"
5556
"github.com/cockroachdb/cockroach/pkg/util/stop"
5657
"github.com/cockroachdb/cockroach/pkg/util/syncutil"
@@ -324,9 +325,14 @@ func NewTestCluster(
324325
t.Fatal("StartSingleNode implies 1 node only, but asked to create", nodes)
325326
}
326327
if clusterArgs.ServerArgs.ClusterName == "" {
328+
// NB: not using randutil.NewTestRand which deterministically depends on the
329+
// testing seed. It would defeat the ClusterName's purpose (prevent messages
330+
// across TestClusters), e.g. if a test is stressed with the same seed.
331+
rng := rand.New(rand.NewSource(rand.Int63()))
327332
// Use a cluster name that is sufficiently unique (within the CI env) but is
328333
// concise and recognizable.
329-
clusterArgs.ServerArgs.ClusterName = fmt.Sprintf("TestCluster-%d", rand.Uint32())
334+
clusterArgs.ServerArgs.ClusterName = fmt.Sprintf("TestCluster-%s",
335+
randutil.RandString(rng, 10, randutil.PrintableKeyAlphabet))
330336
}
331337

332338
if err := checkServerArgsForCluster(

0 commit comments

Comments
 (0)