Skip to content

Commit 9413682

Browse files
committed
testutils: add DeploymentMode method to ApplicationLayerInterface
Certain tests need to determine the deployment mode of the test server—whether it's single-tenant, shared-process, or external-process. While this can be queried via SQL, a dedicated helper method improves usability. This commit adds `DeploymentMode` to `ApplicationLayerInterface` to provide a simpler way to retrieve this information. Informs: #138912 Epic: CRDB-38970 Release note: None
1 parent 9598211 commit 9413682

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

pkg/server/testserver.go

+15
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,9 @@ type testTenant struct {
910910
// pgPreServer handles SQL connections prior to routing them to a
911911
// specific tenant.
912912
pgPreServer *pgwire.PreServeConnHandler
913+
// deploymentMode specifies the tenant's deployment mode.
914+
// Allowed values: ExternalProcess or SharedProcess.
915+
deploymentMode serverutils.DeploymentMode
913916
}
914917

915918
var _ serverutils.ApplicationLayerInterface = &testTenant{}
@@ -1258,6 +1261,11 @@ func (t *testTenant) SettingsWatcher() interface{} {
12581261
return t.sql.settingsWatcher
12591262
}
12601263

1264+
// DeploymentMode is part of the serverutils.ApplicationLayerInterface.
1265+
func (t *testTenant) DeploymentMode() serverutils.DeploymentMode {
1266+
return t.deploymentMode
1267+
}
1268+
12611269
// WaitForTenantCapabilities is part of the serverutils.TenantControlInterface.
12621270
func (ts *testServer) WaitForTenantCapabilities(
12631271
ctx context.Context,
@@ -1415,6 +1423,7 @@ func (ts *testServer) StartSharedProcessTenant(
14151423
pgL: sqlServerWrapper.loopbackPgL,
14161424
httpTestServer: hts,
14171425
drain: sqlServerWrapper.drainServer,
1426+
deploymentMode: serverutils.SharedProcess,
14181427
}
14191428

14201429
sqlDB, err := ts.SQLConnE(serverutils.DBName("cluster:" + string(args.TenantName) + "/" + args.UseDatabase))
@@ -1791,6 +1800,7 @@ func (ts *testServer) StartTenant(
17911800
http: sw.http,
17921801
drain: sw.drainServer,
17931802
pgL: sw.loopbackPgL,
1803+
deploymentMode: serverutils.ExternalProcess,
17941804
}, err
17951805
}
17961806

@@ -1920,6 +1930,11 @@ func (ts *testServer) MustGetSQLNetworkCounter(name string) int64 {
19201930
return mustGetSQLCounterForRegistry(reg, name)
19211931
}
19221932

1933+
// DeploymentMode is part of the serverutils.ApplicationLayerInterface.
1934+
func (ts *testServer) DeploymentMode() serverutils.DeploymentMode {
1935+
return serverutils.SingleTenant
1936+
}
1937+
19231938
// Locality is part of the serverutils.ApplicationLayerInterface.
19241939
func (ts *testServer) Locality() roachpb.Locality {
19251940
return ts.cfg.Locality

pkg/testutils/serverutils/api.go

+16
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,17 @@ type TestServerController interface {
130130
RunInitialSQL(ctx context.Context, startSingleNode bool, adminUser, adminPassword string) error
131131
}
132132

133+
// DeploymentMode defines the mode of the underlying test server or tenant,
134+
// which can be single-tenant (system-only), shared-process, or
135+
// external-process.
136+
type DeploymentMode uint8
137+
138+
const (
139+
SingleTenant DeploymentMode = iota
140+
SharedProcess
141+
ExternalProcess
142+
)
143+
133144
// ApplicationLayerInterface defines accessors to the application
134145
// layer of a test server. Tests written against this interface are
135146
// effectively agnostic to whether they use a virtual cluster or not.
@@ -451,6 +462,11 @@ type ApplicationLayerInterface interface {
451462

452463
// DistSQLPlanningNodeID returns the NodeID to use by the DistSQL span resolver.
453464
DistSQLPlanningNodeID() roachpb.NodeID
465+
466+
// DeploymentMode returns the deployment mode of the underlying server or
467+
// tenant, which can be single-tenant (system-only), shared-process, or
468+
// external-process.
469+
DeploymentMode() DeploymentMode
454470
}
455471

456472
// TenantControlInterface defines the API of a test server that can

0 commit comments

Comments
 (0)