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.

Part of: #106311
Release note: None
  • Loading branch information
wenyihu6 committed Jul 21, 2023
1 parent 4156a03 commit 0b1bf9a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
3 changes: 2 additions & 1 deletion pkg/kv/kvserver/asim/tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ go_library(
"assert.go",
"default_settings.go",
"rand_framework.go",
"rand_settings.go",
"rand_gen.go",
],
importpath = "github.com/cockroachdb/cockroach/pkg/kv/kvserver/asim/tests",
visibility = ["//visibility:public"],
Expand All @@ -45,6 +45,7 @@ go_library(
"//pkg/kv/kvserver/asim/event",
"//pkg/kv/kvserver/asim/gen",
"//pkg/kv/kvserver/asim/metrics",
"//pkg/kv/kvserver/asim/state",
"//pkg/roachpb",
"//pkg/spanconfig/spanconfigtestutils",
"//pkg/util/log",
Expand Down
4 changes: 2 additions & 2 deletions pkg/kv/kvserver/asim/tests/rand_framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,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 Expand Up @@ -134,7 +134,7 @@ func (f randTestingFramework) runRandTestRepeated(t *testing.T) {
}
}

// Helper Functo
// Helper Function
// loadClusterInfo creates a LoadedCluster from a matching ClusterInfo based on
// the given configNam, or panics if no match is found in existing
// configurations.
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 randomly picks a 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 @@ -42,7 +42,7 @@ func defaultSettings(randOptions map[string]bool) testSettings {
// for output + add more tests to cover cases that are not tested by default
func TestRandomized(t *testing.T) {
randOptions := map[string]bool{
"cluster": false,
"cluster": true,
"ranges": false,
"load": false,
"static_settings": false,
Expand Down

0 comments on commit 0b1bf9a

Please sign in to comment.