Skip to content

Commit

Permalink
testserver: add ShareMostTestingKnobsWithTenant option
Browse files Browse the repository at this point in the history
The new ShareMostTestingKnobs copies nearly all of the testing knobs
specified for a TestServer to any tenant started for that server.

The goal here is to make it easier to write tests that depend on
testing hooks that work under probabilistic tenant testing.

Release justification: non-production code change

Release note: None
  • Loading branch information
stevendanna committed Sep 23, 2022
1 parent 48af844 commit 11b7ea9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
6 changes: 6 additions & 0 deletions pkg/base/test_server_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ type TestServerArgs struct {
// or if some of the functionality being tested is not accessible from
// within tenants.
DisableDefaultTestTenant bool

// ShareMostTestingKnobsWithTenant should be set by tests that want their
// testing knobs shared with the any DefaultTestTenant that the server starts.
// See (*testserver).TestingKnobsForTenant for details on which knobs aren't
// shared.
ShareMostTestingKnobsWithTenant bool
}

// TestClusterArgs contains the parameters one can set when creating a test
Expand Down
19 changes: 17 additions & 2 deletions pkg/server/testserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,17 @@ func (ts *TestServer) TestingKnobs() *base.TestingKnobs {
return nil
}

// TestingKnobsForTenant returns a TestingKnobs that is used when starting Test
// Tenants. These knobs are a copy of the Server's TestingKnobs with any knobs
// that have been found to be problematic to share by default removed.
func (ts *TestServer) TestingKnobsForTenant() base.TestingKnobs {
knobs := *ts.TestingKnobs()
// TODO(ssd): We don't share the Server knobs the testcluster setup code
// installed an RPC listener that is inappropriate for the tenant.
knobs.Server = nil
return knobs
}

// TenantStatusServer returns the TenantStatusServer used by the TestServer.
func (ts *TestServer) TenantStatusServer() interface{} {
return ts.status
Expand Down Expand Up @@ -546,10 +557,14 @@ func (ts *TestServer) maybeStartDefaultTestTenant(ctx context.Context) error {
UseDatabase: ts.params.UseDatabase,
SSLCertsDir: ts.params.SSLCertsDir,
AllowSettingClusterSettings: true,
}
if ts.params.ShareMostTestingKnobsWithTenant {
params.TestingKnobs = ts.TestingKnobsForTenant()
} else {
// These settings are inherited from the SQL server creation in
// logicTest.newCluster, and are required to run the logic test suite
// successfully.
TestingKnobs: base.TestingKnobs{
params.TestingKnobs = base.TestingKnobs{
SQLExecutor: &sql.ExecutorTestingKnobs{
DeterministicExplain: true,
UseTransactionalDescIDGenerator: useTransactionalDescIDGenerator,
Expand All @@ -558,7 +573,7 @@ func (ts *TestServer) maybeStartDefaultTestTenant(ctx context.Context) error {
AOSTClause: "AS OF SYSTEM TIME '-1us'",
},
RangeFeed: ts.TestingKnobs().RangeFeed,
},
}
}

tenant, err := ts.StartTenant(ctx, params)
Expand Down

0 comments on commit 11b7ea9

Please sign in to comment.