Skip to content

Commit

Permalink
asim: add random predefined cluster config selection
Browse files Browse the repository at this point in the history
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: #106311
Release note: None
  • Loading branch information
wenyihu6 committed Aug 1, 2023
1 parent cbfd757 commit a0e0ea3
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions pkg/kv/kvserver/asim/tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ go_library(
"assert.go",
"default_settings.go",
"rand_framework.go",
"rand_gen.go",
],
importpath = "github.com/cockroachdb/cockroach/pkg/kv/kvserver/asim/tests",
visibility = ["//visibility:public"],
Expand Down
2 changes: 1 addition & 1 deletion pkg/kv/kvserver/asim/tests/rand_framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (f randTestingFramework) getCluster() gen.ClusterGen {
if !f.s.randOptions.cluster {
return defaultBasicClusterGen()
}
return gen.BasicCluster{}
return f.randomClusterInfoGen(f.s.randSource)
}

func (f randTestingFramework) getRanges() gen.RangeGen {
Expand Down
25 changes: 25 additions & 0 deletions pkg/kv/kvserver/asim/tests/rand_gen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2023 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package tests

import (
"math/rand"

"github.com/cockroachdb/cockroach/pkg/kv/kvserver/asim/gen"
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/asim/state"
)

// randomClusterInfoGen returns a randomly picked predefined configuration.
func (f randTestingFramework) randomClusterInfoGen(randSource *rand.Rand) gen.LoadedCluster {
chosenIndex := randSource.Intn(len(state.ClusterOptions))
chosenType := state.ClusterOptions[chosenIndex]
return loadClusterInfo(chosenType)
}
2 changes: 1 addition & 1 deletion pkg/kv/kvserver/asim/tests/rand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func defaultSettings(randOptions testRandOptions) testSettings {
// default
func TestRandomized(t *testing.T) {
randOptions := testRandOptions{
cluster: false,
cluster: true,
ranges: false,
load: false,
staticSettings: false,
Expand Down

0 comments on commit a0e0ea3

Please sign in to comment.