Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testutils: move tenant or server logic into test server #98844

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions pkg/server/testserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -1640,6 +1640,19 @@ func (ts *TestServer) ExecutorConfig() interface{} {
return *ts.sqlServer.execCfg
}

// StartedDefaultTestTenant is part of the TestServerInterface.
func (ts *TestServer) StartedDefaultTestTenant() bool {
return !ts.cfg.DisableDefaultTestTenant
}

// TenantOrServer is part of the TestServerInterface.
func (ts *TestServer) TenantOrServer() serverutils.TestTenantInterface {
if ts.StartedDefaultTestTenant() {
return ts.testTenants[0]
}
return ts
}

// TracerI is part of the TestServerInterface.
func (ts *TestServer) TracerI() interface{} {
return ts.Tracer()
Expand Down
8 changes: 8 additions & 0 deletions pkg/testutils/serverutils/test_server_shim.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,14 @@ type TestServerInterface interface {

// TestTenants returns the test tenants associated with the server
TestTenants() []TestTenantInterface

// StartedDefaultTestTenant returns true if the server has started the default
// test tenant.
StartedDefaultTestTenant() bool

// TenantOrServer returns the default test tenant, if it was started or this
// server if not.
TenantOrServer() TestTenantInterface
}

// TestServerFactory encompasses the actual implementation of the shim
Expand Down
8 changes: 2 additions & 6 deletions pkg/testutils/testcluster/testcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,13 @@ func (tc *TestCluster) Stopper() *stop.Stopper {
// StartedDefaultTestTenant returns whether this cluster started a default
// test tenant.
func (tc *TestCluster) StartedDefaultTestTenant() bool {
return !tc.Servers[0].Cfg.DisableDefaultTestTenant
return tc.Servers[0].StartedDefaultTestTenant()
}

// TenantOrServer returns either the ith server in the cluster or the tenant server associated with
// the ith server if the cluster started with a default test tenant.
func (tc *TestCluster) TenantOrServer(idx int) serverutils.TestTenantInterface {
s := tc.Server(idx)
if tc.StartedDefaultTestTenant() {
return s.TestTenants()[0]
}
return s
return tc.Server(idx).TenantOrServer()
}

// stopServers stops the stoppers for each individual server in the cluster.
Expand Down