Skip to content

Commit 627e6d3

Browse files
committed
*: use GrantTenantCapabilities helper in tests
We now have this handy helper which can replace older `ALTER TENANT` plus "wait for capabilities" combo (which still happens under the hood). Release note: None
1 parent a69a151 commit 627e6d3

File tree

7 files changed

+37
-70
lines changed

7 files changed

+37
-70
lines changed

pkg/backup/backup_tenant_test.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,9 @@ func TestBackupSharedProcessTenantNodeDown(t *testing.T) {
6464
})
6565
require.NoError(t, err)
6666

67-
hostDB.Exec(t, "ALTER TENANT test GRANT ALL CAPABILITIES")
68-
err = tc.Server(0).TenantController().WaitForTenantCapabilities(ctx, testTenantID, map[tenantcapabilitiespb.ID]string{
69-
tenantcapabilitiespb.CanUseNodelocalStorage: "true",
70-
}, "")
71-
require.NoError(t, err)
67+
tc.GrantTenantCapabilities(
68+
ctx, t, testTenantID,
69+
map[tenantcapabilitiespb.ID]string{tenantcapabilitiespb.CanUseNodelocalStorage: "true"})
7270

7371
tenantSQL := sqlutils.MakeSQLRunner(tenantDB)
7472
tenantSQL.Exec(t, "CREATE TABLE foo AS SELECT generate_series(1, 4000)")

pkg/ccl/serverccl/adminccl/tenant_admin_test.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,9 @@ func testTenantMetricsCapabilityRPC(
8080
require.Error(t, err)
8181

8282
s := helper.HostCluster().Server(0)
83-
db := helper.HostCluster().ServerConn(0)
84-
_, err = db.Exec("ALTER TENANT [10] GRANT CAPABILITY can_view_tsdb_metrics=true\n")
85-
require.NoError(t, err)
86-
capability := map[tenantcapabilitiespb.ID]string{tenantcapabilitiespb.CanViewTSDBMetrics: "true"}
87-
serverutils.WaitForTenantCapabilities(t, s, serverutils.TestTenantID(), capability, "")
83+
require.NoError(t, s.GrantTenantCapabilities(
84+
ctx, serverutils.TestTenantID(),
85+
map[tenantcapabilitiespb.ID]string{tenantcapabilitiespb.CanViewTSDBMetrics: "true"}))
8886

8987
err = http.PostJSONChecked("/ts/query", &query, &queryResp)
9088
require.NoError(t, err)
@@ -104,10 +102,9 @@ func testTenantMetricsCapabilityRPC(
104102
err = http.PostJSONChecked("/ts/query", &query, &queryResp)
105103
require.Error(t, err)
106104

107-
_, err = db.Exec("ALTER TENANT [10] GRANT CAPABILITY can_view_all_metrics=true\n")
108-
require.NoError(t, err)
109-
capability = map[tenantcapabilitiespb.ID]string{tenantcapabilitiespb.CanViewAllMetrics: "true"}
110-
serverutils.WaitForTenantCapabilities(t, s, serverutils.TestTenantID(), capability, "")
105+
require.NoError(t, s.GrantTenantCapabilities(
106+
ctx, serverutils.TestTenantID(),
107+
map[tenantcapabilitiespb.ID]string{tenantcapabilitiespb.CanViewAllMetrics: "true"}))
111108

112109
err = http.PostJSONChecked("/ts/query", &query, &queryResp)
113110
require.NoError(t, err)

pkg/ccl/serverccl/server_sql_test.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -283,12 +283,9 @@ func TestTenantProcessDebugging(t *testing.T) {
283283
require.Equal(t, http.StatusForbidden, resp.StatusCode)
284284
require.Contains(t, string(body), "tenant does not have capability to debug the running process")
285285

286-
_, err = db.Exec(`ALTER TENANT processdebug GRANT CAPABILITY can_debug_process=true`)
287-
require.NoError(t, err)
288-
289-
serverutils.WaitForTenantCapabilities(t, s, serverutils.TestTenantID(), map[tenantcapabilitiespb.ID]string{
290-
tenantcapabilitiespb.CanDebugProcess: "true",
291-
}, "")
286+
require.NoError(t, s.GrantTenantCapabilities(
287+
ctx, serverutils.TestTenantID(),
288+
map[tenantcapabilitiespb.ID]string{tenantcapabilitiespb.CanDebugProcess: "true"}))
292289
}
293290
resp, err := httpClient.Get(url.String())
294291
require.NoError(t, err)
@@ -326,12 +323,9 @@ func TestTenantProcessDebugging(t *testing.T) {
326323
require.Equal(t, http.StatusForbidden, resp.StatusCode)
327324
require.Contains(t, string(body), "tenant does not have capability to debug the running process")
328325

329-
_, err = db.Exec(`ALTER TENANT processdebug GRANT CAPABILITY can_debug_process=true`)
330-
require.NoError(t, err)
331-
332-
serverutils.WaitForTenantCapabilities(t, s, serverutils.TestTenantID(), map[tenantcapabilitiespb.ID]string{
333-
tenantcapabilitiespb.CanDebugProcess: "true",
334-
}, "")
326+
require.NoError(t, s.GrantTenantCapabilities(
327+
ctx, serverutils.TestTenantID(),
328+
map[tenantcapabilitiespb.ID]string{tenantcapabilitiespb.CanDebugProcess: "true"}))
335329
}
336330
resp, err := httpClient.Get(url.String())
337331
require.NoError(t, err)

pkg/server/storage_api/gossip_test.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,13 @@ func TestStatusGossipJson(t *testing.T) {
2424
defer leaktest.AfterTest(t)()
2525
defer log.Scope(t).Close(t)
2626

27-
srv := serverutils.StartServerOnly(t, base.TestServerArgs{
28-
DefaultTestTenant: base.TestTenantProbabilisticOnly,
29-
})
27+
srv := serverutils.StartServerOnly(t, base.TestServerArgs{})
3028
defer srv.Stopper().Stop(context.Background())
3129

32-
if srv.TenantController().StartedDefaultTestTenant() {
33-
// explicitly enabling CanViewNodeInfo capability for the secondary/application tenant
34-
_, err := srv.SystemLayer().SQLConn(t).Exec(
35-
`ALTER TENANT [$1] GRANT CAPABILITY can_view_node_info=true`,
36-
serverutils.TestTenantID().ToUint64(),
37-
)
38-
require.NoError(t, err)
39-
serverutils.WaitForTenantCapabilities(t, srv, serverutils.TestTenantID(),
40-
map[tenantcapabilitiespb.ID]string{tenantcapabilitiespb.CanViewNodeInfo: "true"}, "")
30+
if srv.DeploymentMode().IsExternal() {
31+
require.NoError(t, srv.GrantTenantCapabilities(
32+
context.Background(), serverutils.TestTenantID(),
33+
map[tenantcapabilitiespb.ID]string{tenantcapabilitiespb.CanViewNodeInfo: "true"}))
4134
}
4235
s := srv.ApplicationLayer()
4336
require.NoError(t, validateGossipResponse(s))

pkg/sql/gcjob/gc_job_test.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,10 @@ func TestDropRemovesManualSplits(t *testing.T) {
123123
s, db, _ := serverutils.StartServer(t, base.TestServerArgs{})
124124
defer s.Stopper().Stop(ctx)
125125

126-
if s.TenantController().StartedDefaultTestTenant() {
127-
tenID := serverutils.TestTenantID()
128-
_, err := s.SystemLayer().SQLConn(t).Exec(
129-
"ALTER TENANT [$1] GRANT CAPABILITY can_admin_unsplit", tenID.ToUint64())
130-
require.NoError(t, err)
131-
132-
expCaps := map[tenantcapabilitiespb.ID]string{tenantcapabilitiespb.CanAdminUnsplit: "true"}
133-
serverutils.WaitForTenantCapabilities(t, s, tenID, expCaps, "admin_unsplit")
126+
if s.DeploymentMode().IsExternal() {
127+
require.NoError(t, s.GrantTenantCapabilities(
128+
ctx, serverutils.TestTenantID(),
129+
map[tenantcapabilitiespb.ID]string{tenantcapabilitiespb.CanAdminUnsplit: "true"}))
134130
}
135131

136132
sqlDB := sqlutils.MakeSQLRunner(db)

pkg/sql/tests/rsg_test.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -916,16 +916,13 @@ func testRandomSyntax(
916916
}
917917
srv, rawDB, _ := serverutils.StartServer(t, params)
918918
defer srv.Stopper().Stop(ctx)
919-
if srv.StartedDefaultTestTenant() {
920-
// If we started a test tenant, then disable rate limiting for it (we're
921-
// going to be slamming the server with many queries, and we don't want
922-
// for them to be artificially delayed).
923-
tenID := serverutils.TestTenantID()
924-
_, err := srv.SystemLayer().SQLConn(t).Exec(
925-
"ALTER TENANT [$1] GRANT CAPABILITY exempt_from_rate_limiting", tenID.ToUint64())
926-
require.NoError(t, err)
927-
expCaps := map[tenantcapabilitiespb.ID]string{tenantcapabilitiespb.ExemptFromRateLimiting: "true"}
928-
serverutils.WaitForTenantCapabilities(t, srv, tenID, expCaps, "exempt_from_rate_limiting")
919+
if srv.DeploymentMode().IsExternal() {
920+
// If we're in the external-process mode, then disable rate limiting for
921+
// it (we're going to be slamming the server with many queries, and we
922+
// don't want for them to be artificially delayed).
923+
require.NoError(t, srv.GrantTenantCapabilities(
924+
ctx, serverutils.TestTenantID(),
925+
map[tenantcapabilitiespb.ID]string{tenantcapabilitiespb.ExemptFromRateLimiting: "true"}))
929926
}
930927
db := &verifyFormatDB{db: rawDB}
931928
// If the test fails we can log the previous set of statements.

pkg/ts/server_test.go

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,6 @@ func TestServerQueryTenant(t *testing.T) {
305305
})
306306
defer s.Stopper().Stop(context.Background())
307307

308-
systemDB := s.SystemLayer().SQLConn(t)
309-
310308
// This metric exists in the tenant registry since it's SQL-specific.
311309
tenantMetricName := "sql.insert.count"
312310
// This metric exists only in the host/system registry since it's process-level.
@@ -571,12 +569,9 @@ func TestServerQueryTenant(t *testing.T) {
571569
}
572570

573571
tenant, _ := serverutils.StartTenant(t, s, base.TestTenantArgs{TenantID: tenantID})
574-
_, err = systemDB.Exec("ALTER TENANT [2] GRANT CAPABILITY can_view_tsdb_metrics=true;\n")
575-
if err != nil {
576-
t.Fatal(err)
577-
}
578-
capability := map[tenantcapabilitiespb.ID]string{tenantcapabilitiespb.CanViewTSDBMetrics: "true"}
579-
serverutils.WaitForTenantCapabilities(t, s, tenantID, capability, "")
572+
require.NoError(t, s.GrantTenantCapabilities(
573+
context.Background(), tenantID,
574+
map[tenantcapabilitiespb.ID]string{tenantcapabilitiespb.CanViewTSDBMetrics: "true"}))
580575
tenantConn := tenant.RPCClientConn(t, username.RootUserName())
581576
tenantClient := tenantConn.NewTimeSeriesClient()
582577

@@ -638,12 +633,9 @@ func TestServerQueryTenant(t *testing.T) {
638633
},
639634
},
640635
}
641-
_, err = systemDB.Exec("ALTER TENANT [2] GRANT CAPABILITY can_view_all_metrics=true;\n")
642-
if err != nil {
643-
t.Fatal(err)
644-
}
645-
capability = map[tenantcapabilitiespb.ID]string{tenantcapabilitiespb.CanViewAllMetrics: "true"}
646-
serverutils.WaitForTenantCapabilities(t, s, tenantID, capability, "")
636+
require.NoError(t, s.GrantTenantCapabilities(
637+
context.Background(), tenantID,
638+
map[tenantcapabilitiespb.ID]string{tenantcapabilitiespb.CanViewAllMetrics: "true"}))
647639

648640
tenantResponse, err = tenantClient.Query(context.Background(), &tspb.TimeSeriesQueryRequest{
649641
StartNanos: 400 * 1e9,

0 commit comments

Comments
 (0)