Skip to content

Commit 49374d4

Browse files
committed
server,testutils: remove complexity
There is a saying (paraphrasing) that it always takes more work removing unwanted complexity than it takes to add it. This is an example of that. Prior to this commit, there was an "interesting" propagation of the flag that decides whether or not to define a test tenant for test servers and clusters. In a nutshell, we had: - an "input" flag in `base.TestServerArgs`, which remained mostly immutable - a boolean decided once by `ShouldStartDefaultTestTenant()` either in: - `serverutils.StartServerOnlyE` - or `testcluster.Start` - that boolean choice was then propagated to `server.testServer` via _another_ boolean config flag in `server.BaseConfig` - both the 2nd boolean and the original input flag were then again checked when the time came to do the work (in `maybeStartDefaultTestTenant`). Additional complexity was then incurred by the need of `TestCluster` to make the determination just once (and not once per server). This commit cuts through all the layers of complexity by simply propagating the choice of `ShouldStartDefaultTestTenant()` back into the `TestServerArgs` and only ever reading from that subsequently. Release note: None
1 parent 1fd3eb8 commit 49374d4

File tree

17 files changed

+177
-154
lines changed

17 files changed

+177
-154
lines changed

pkg/base/test_server_args.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,6 @@ var (
281281

282282
// InternalNonDefaultDecision is a sentinel value used inside a
283283
// mechanism in serverutils. Should not be used by tests directly.
284-
//
285-
// TODO(#76378): Investigate how we can remove the need for this
286-
// sentinel value.
287284
InternalNonDefaultDecision = DefaultTestTenantOptions{testBehavior: ttDisabled, allowAdditionalTenants: true}
288285
)
289286

pkg/ccl/backupccl/backup_test.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,11 @@ func TestBackupRestorePartitioned(t *testing.T) {
337337

338338
// Disabled to run within tenant as certain MR features are not available to tenants.
339339
args := base.TestClusterArgs{
340+
ServerArgs: base.TestServerArgs{
341+
DefaultTestTenant: base.TODOTestTenantDisabled,
342+
},
340343
ServerArgsPerNode: map[int]base.TestServerArgs{
341344
0: {
342-
DefaultTestTenant: base.TODOTestTenantDisabled,
343345
Locality: roachpb.Locality{Tiers: []roachpb.Tier{
344346
{Key: "region", Value: "west"},
345347
// NB: This has the same value as an az in the east region
@@ -349,7 +351,6 @@ func TestBackupRestorePartitioned(t *testing.T) {
349351
}},
350352
},
351353
1: {
352-
DefaultTestTenant: base.TODOTestTenantDisabled,
353354
Locality: roachpb.Locality{Tiers: []roachpb.Tier{
354355
{Key: "region", Value: "east"},
355356
// NB: This has the same value as an az in the west region
@@ -359,7 +360,6 @@ func TestBackupRestorePartitioned(t *testing.T) {
359360
}},
360361
},
361362
2: {
362-
DefaultTestTenant: base.TODOTestTenantDisabled,
363363
Locality: roachpb.Locality{Tiers: []roachpb.Tier{
364364
{Key: "region", Value: "east"},
365365
{Key: "az", Value: "az2"},
@@ -490,34 +490,33 @@ func TestBackupRestoreExecLocality(t *testing.T) {
490490

491491
// Disabled to run within tenant as certain MR features are not available to tenants.
492492
args := base.TestClusterArgs{
493+
ServerArgs: base.TestServerArgs{
494+
DefaultTestTenant: base.TODOTestTenantDisabled,
495+
},
493496
ServerArgsPerNode: map[int]base.TestServerArgs{
494497
0: {
495-
ExternalIODir: "/west0",
496-
DefaultTestTenant: base.TODOTestTenantDisabled,
498+
ExternalIODir: "/west0",
497499
Locality: roachpb.Locality{Tiers: []roachpb.Tier{
498500
{Key: "tier", Value: "0"},
499501
{Key: "region", Value: "west"},
500502
}},
501503
},
502504
1: {
503-
ExternalIODir: "/west1",
504-
DefaultTestTenant: base.TODOTestTenantDisabled,
505+
ExternalIODir: "/west1",
505506
Locality: roachpb.Locality{Tiers: []roachpb.Tier{
506507
{Key: "tier", Value: "1"},
507508
{Key: "region", Value: "west"},
508509
}},
509510
},
510511
2: {
511-
ExternalIODir: "/east0",
512-
DefaultTestTenant: base.TODOTestTenantDisabled,
512+
ExternalIODir: "/east0",
513513
Locality: roachpb.Locality{Tiers: []roachpb.Tier{
514514
{Key: "tier", Value: "0"},
515515
{Key: "region", Value: "east"},
516516
}},
517517
},
518518
3: {
519-
ExternalIODir: "/east1",
520-
DefaultTestTenant: base.TODOTestTenantDisabled,
519+
ExternalIODir: "/east1",
521520
Locality: roachpb.Locality{Tiers: []roachpb.Tier{
522521
{Key: "tier", Value: "1"},
523522
{Key: "region", Value: "east"},

pkg/ccl/changefeedccl/changefeed_test.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5689,10 +5689,7 @@ func TestChangefeedHandlesRollingRestart(t *testing.T) {
56895689
nodeDrainChannels[n].Store(make(chan struct{}))
56905690

56915691
return base.TestServerArgs{
5692-
// Test uses SPLIT AT, which isn't currently supported for
5693-
// secondary tenants. Tracked with #76378.
5694-
DefaultTestTenant: base.TODOTestTenantDisabled,
5695-
UseDatabase: "test",
5692+
UseDatabase: "test",
56965693
Knobs: base.TestingKnobs{
56975694
DistSQL: &execinfra.TestingKnobs{
56985695
DrainFast: true,
@@ -5770,6 +5767,11 @@ func TestChangefeedHandlesRollingRestart(t *testing.T) {
57705767
}
57715768
return perNode
57725769
}(),
5770+
ServerArgs: base.TestServerArgs{
5771+
// Test uses SPLIT AT, which isn't currently supported for
5772+
// secondary tenants. Tracked with #76378.
5773+
DefaultTestTenant: base.TODOTestTenantDisabled,
5774+
},
57735775
})
57745776
defer tc.Stopper().Stop(context.Background())
57755777

@@ -5882,9 +5884,6 @@ func TestChangefeedPropagatesTerminalError(t *testing.T) {
58825884
perServerKnobs := make(map[int]base.TestServerArgs, numNodes)
58835885
for i := 0; i < numNodes; i++ {
58845886
perServerKnobs[i] = base.TestServerArgs{
5885-
// Test uses SPLIT AT, which isn't currently supported for
5886-
// secondary tenants. Tracked with #76378.
5887-
DefaultTestTenant: base.TODOTestTenantDisabled,
58885887
Knobs: base.TestingKnobs{
58895888
DistSQL: &execinfra.TestingKnobs{
58905889
DrainFast: true,
@@ -5901,6 +5900,11 @@ func TestChangefeedPropagatesTerminalError(t *testing.T) {
59015900
base.TestClusterArgs{
59025901
ServerArgsPerNode: perServerKnobs,
59035902
ReplicationMode: base.ReplicationManual,
5903+
ServerArgs: base.TestServerArgs{
5904+
// Test uses SPLIT AT, which isn't currently supported for
5905+
// secondary tenants. Tracked with #76378.
5906+
DefaultTestTenant: base.TODOTestTenantDisabled,
5907+
},
59045908
})
59055909
defer tc.Stopper().Stop(context.Background())
59065910

@@ -8241,13 +8245,17 @@ func TestChangefeedExecLocality(t *testing.T) {
82418245
str := strconv.Itoa
82428246

82438247
const nodes = 4
8244-
args := base.TestClusterArgs{ServerArgsPerNode: map[int]base.TestServerArgs{}}
8248+
args := base.TestClusterArgs{
8249+
ServerArgs: base.TestServerArgs{
8250+
DefaultTestTenant: base.TODOTestTenantDisabled, // need nodelocal and splits.
8251+
},
8252+
ServerArgsPerNode: map[int]base.TestServerArgs{},
8253+
}
82458254
for i := 0; i < nodes; i++ {
82468255
args.ServerArgsPerNode[i] = base.TestServerArgs{
82478256
ExternalIODir: path.Join(dir, str(i)),
82488257
Locality: roachpb.Locality{
82498258
Tiers: []roachpb.Tier{{Key: "x", Value: str(i / 2)}, {Key: "y", Value: str(i % 2)}}},
8250-
DefaultTestTenant: base.TODOTestTenantDisabled, // need nodelocal and splits.
82518259
}
82528260
}
82538261

pkg/ccl/kvccl/kvfollowerreadsccl/boundedstaleness_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,14 +268,16 @@ func TestBoundedStalenessDataDriven(t *testing.T) {
268268
ctx := context.Background()
269269

270270
clusterArgs := base.TestClusterArgs{
271+
ServerArgs: base.TestServerArgs{
272+
DefaultTestTenant: base.TODOTestTenantDisabled,
273+
},
271274
ServerArgsPerNode: map[int]base.TestServerArgs{},
272275
}
273276
const numNodes = 3
274277
var bse boundedStalenessEvents
275278
for i := 0; i < numNodes; i++ {
276279
i := i
277280
clusterArgs.ServerArgsPerNode[i] = base.TestServerArgs{
278-
DefaultTestTenant: base.TODOTestTenantDisabled,
279281
Knobs: base.TestingKnobs{
280282
SQLExecutor: &sql.ExecutorTestingKnobs{
281283
WithStatementTrace: func(trace tracingpb.Recording, stmt string) {

pkg/ccl/kvccl/kvfollowerreadsccl/followerreads_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -714,8 +714,7 @@ func TestFollowerReadsWithStaleDescriptor(t *testing.T) {
714714
// Also, we're going to collect a trace of the test's final query.
715715
ServerArgsPerNode: map[int]base.TestServerArgs{
716716
3: {
717-
DefaultTestTenant: base.TODOTestTenantDisabled,
718-
UseDatabase: "t",
717+
UseDatabase: "t",
719718
Knobs: base.TestingKnobs{
720719
KVClient: &kvcoord.ClientTestingKnobs{
721720
// Inhibit the checking of connection health done by the
@@ -901,13 +900,15 @@ func TestSecondaryTenantFollowerReadsRouting(t *testing.T) {
901900
}
902901
localities[i] = locality
903902
serverArgs[i] = base.TestServerArgs{
904-
Locality: localities[i],
905-
DefaultTestTenant: base.TODOTestTenantDisabled, // we'll create one ourselves below.
903+
Locality: localities[i],
906904
}
907905
}
908906
tc := testcluster.StartTestCluster(t, numNodes, base.TestClusterArgs{
909907
ReplicationMode: base.ReplicationManual,
910908
ServerArgsPerNode: serverArgs,
909+
ServerArgs: base.TestServerArgs{
910+
DefaultTestTenant: base.TODOTestTenantDisabled, // we'll create one ourselves below.
911+
},
911912
})
912913
ctx := context.Background()
913914
defer tc.Stopper().Stop(ctx)

pkg/ccl/multiregionccl/cold_start_latency_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ func TestColdStartLatency(t *testing.T) {
7979
for i := 0; i < numNodes; i++ {
8080
i := i
8181
args := base.TestServerArgs{
82-
DefaultTestTenant: base.TODOTestTenantDisabled,
83-
Locality: localities[i],
82+
Locality: localities[i],
8483
}
8584
signalAfter[i] = make(chan struct{})
8685
serverKnobs := &server.TestingKnobs{
@@ -120,6 +119,9 @@ func TestColdStartLatency(t *testing.T) {
120119
tc := testcluster.NewTestCluster(t, numNodes, base.TestClusterArgs{
121120
ParallelStart: true,
122121
ServerArgsPerNode: perServerArgs,
122+
ServerArgs: base.TestServerArgs{
123+
DefaultTestTenant: base.TODOTestTenantDisabled,
124+
},
123125
})
124126
go func() {
125127
for _, c := range signalAfter {

pkg/ccl/multiregionccl/datadriven_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,6 @@ func TestMultiRegionDataDriven(t *testing.T) {
153153
}
154154
serverArgs[i] = base.TestServerArgs{
155155
Locality: localityCfg,
156-
// We need to disable the default test tenant here
157-
// because it appears as though operations like
158-
// "wait-for-zone-config-changes" only work correctly
159-
// when called from the system tenant. More
160-
// investigation is required (tracked with #76378).
161-
DefaultTestTenant: base.TODOTestTenantDisabled,
162156
Knobs: base.TestingKnobs{
163157
SQLExecutor: &sql.ExecutorTestingKnobs{
164158
WithStatementTrace: func(trace tracingpb.Recording, stmt string) {
@@ -175,6 +169,14 @@ func TestMultiRegionDataDriven(t *testing.T) {
175169
numServers := len(localityNames)
176170
tc := testcluster.StartTestCluster(t, numServers, base.TestClusterArgs{
177171
ServerArgsPerNode: serverArgs,
172+
ServerArgs: base.TestServerArgs{
173+
// We need to disable the default test tenant here
174+
// because it appears as though operations like
175+
// "wait-for-zone-config-changes" only work correctly
176+
// when called from the system tenant. More
177+
// investigation is required (tracked with #76378).
178+
DefaultTestTenant: base.TODOTestTenantDisabled,
179+
},
178180
})
179181
ds.tc = tc
180182

pkg/ccl/multiregionccl/multiregionccltestutils/testutils.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,6 @@ func TestingCreateMultiRegionClusterWithRegionList(
110110
Knobs: knobs,
111111
ExternalIODir: params.baseDir,
112112
UseDatabase: params.useDatabase,
113-
// Disabling this due to failures in the rtt_analysis tests. Ideally
114-
// we could disable multi-tenancy just for those tests, but this function
115-
// is used to create the MR cluster for all test cases. For
116-
// bonus points, the code to re-enable this should also provide more
117-
// flexibility in disabling the default test tenant by callers of this
118-
// function. Re-enablement is tracked with #76378.
119-
DefaultTestTenant: base.TODOTestTenantDisabled,
120113
Locality: roachpb.Locality{
121114
Tiers: []roachpb.Tier{{Key: "region", Value: region}},
122115
},
@@ -128,6 +121,15 @@ func TestingCreateMultiRegionClusterWithRegionList(
128121
tc := testcluster.StartTestCluster(t, totalServerCount, base.TestClusterArgs{
129122
ReplicationMode: params.replicationMode,
130123
ServerArgsPerNode: serverArgs,
124+
ServerArgs: base.TestServerArgs{
125+
// Disabling this due to failures in the rtt_analysis tests. Ideally
126+
// we could disable multi-tenancy just for those tests, but this function
127+
// is used to create the MR cluster for all test cases. For
128+
// bonus points, the code to re-enable this should also provide more
129+
// flexibility in disabling the default test tenant by callers of this
130+
// function. Re-enablement is tracked with #76378.
131+
DefaultTestTenant: base.TODOTestTenantDisabled,
132+
},
131133
})
132134

133135
ctx := context.Background()

pkg/server/config.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,6 @@ type BaseConfig struct {
204204
// Environment Variable: COCKROACH_DISABLE_SPAN_CONFIGS
205205
SpanConfigsDisabled bool
206206

207-
// Disables the default test tenant.
208-
DisableDefaultTestTenant bool
209-
210207
// TestingKnobs is used for internal test controls only.
211208
TestingKnobs base.TestingKnobs
212209

pkg/server/multi_store_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,12 @@ func TestAddNewStoresToExistingNodes(t *testing.T) {
6262
// again explicitly.
6363
ReplicationMode: base.ReplicationAuto,
6464
ServerArgsPerNode: map[int]base.TestServerArgs{},
65+
ServerArgs: base.TestServerArgs{
66+
DefaultTestTenant: base.TODOTestTenantDisabled,
67+
},
6568
}
6669
for srvIdx := 0; srvIdx < numNodes; srvIdx++ {
67-
serverArgs := base.TestServerArgs{
68-
DefaultTestTenant: base.TODOTestTenantDisabled,
69-
}
70+
serverArgs := base.TestServerArgs{}
7071
serverArgs.Knobs.Server = &server.TestingKnobs{StickyVFSRegistry: ser}
7172
for storeIdx := 0; storeIdx < numStoresPerNode; storeIdx++ {
7273
id := fmt.Sprintf("s%d.%d", srvIdx+1, storeIdx+1)

0 commit comments

Comments
 (0)