Skip to content

Commit 7a6867c

Browse files
committed
asim: add random predefined cluster config selection
This patch takes the first step towards a randomized framework by enabling asim testing to randomly select a cluster information configuration from a set of predefined choices. These choices are hardcoded and represent common cluster configurations. TestRandomized now takes in `true` for randOptions.cluster to enable random cluster config selection. This provides two modes for cluster generation: 1. Default: currently set to 3 nodes and 1 store per node 2. Random: randomly select a predefined cluster info Part of: cockroachdb#106311 Release note: None
1 parent 05ad3c4 commit 7a6867c

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

pkg/kv/kvserver/asim/tests/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ go_library(
3636
"assert.go",
3737
"default_settings.go",
3838
"rand_framework.go",
39+
"rand_gen.go",
3940
],
4041
importpath = "github.com/cockroachdb/cockroach/pkg/kv/kvserver/asim/tests",
4142
visibility = ["//visibility:public"],

pkg/kv/kvserver/asim/tests/rand_framework.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (f randTestingFramework) getCluster() gen.ClusterGen {
5050
if !f.s.randOptions.cluster {
5151
return defaultBasicClusterGen()
5252
}
53-
return gen.BasicCluster{}
53+
return f.randomClusterInfoGen(f.s.randSource)
5454
}
5555

5656
func (f randTestingFramework) getRanges() gen.RangeGen {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2023 The Cockroach Authors.
2+
//
3+
// Use of this software is governed by the Business Source License
4+
// included in the file licenses/BSL.txt.
5+
//
6+
// As of the Change Date specified in that file, in accordance with
7+
// the Business Source License, use of this software will be governed
8+
// by the Apache License, Version 2.0, included in the file
9+
// licenses/APL.txt.
10+
11+
package tests
12+
13+
import (
14+
"math/rand"
15+
16+
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/asim/gen"
17+
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/asim/state"
18+
)
19+
20+
// randomClusterInfoGen returns a randomly picked predefined configuration.
21+
func (f randTestingFramework) randomClusterInfoGen(randSource *rand.Rand) gen.LoadedCluster {
22+
chosenIndex := randSource.Intn(len(state.ClusterOptions))
23+
chosenType := state.ClusterOptions[chosenIndex]
24+
return loadClusterInfo(chosenType)
25+
}

pkg/kv/kvserver/asim/tests/rand_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func defaultSettings(randOptions testRandOptions) testSettings {
7070
// default
7171
func TestRandomized(t *testing.T) {
7272
randOptions := testRandOptions{
73-
cluster: false,
73+
cluster: true,
7474
ranges: false,
7575
load: false,
7676
staticSettings: false,

0 commit comments

Comments
 (0)