From 6035b1a5f63090acc2f11418484906174c47e399 Mon Sep 17 00:00:00 2001 From: Yahor Yuzefovich Date: Fri, 21 Jul 2023 11:50:15 -0700 Subject: [PATCH] cli,userfile,jobs,ptstorage: remove calls to CreateTestServerParams This commit adjusts tests in these package to run with the test tenant. Note that the test tenant won't still run in `cli` because `ccl` isn't linked (I briefly tried, and I think there was an import cycle - the longer term fix is to move tests into `cli_test` package, but it's left for later). Release note: None --- pkg/cli/BUILD.bazel | 1 - pkg/cli/zip_table_registry_test.go | 9 ++--- pkg/cli/zip_test.go | 22 ++++------- pkg/cloud/userfile/BUILD.bazel | 4 +- pkg/cloud/userfile/file_table_storage_test.go | 25 ++++++------ .../filetable/filetabletest/BUILD.bazel | 3 +- .../file_table_read_writer_test.go | 38 +++++++++--------- .../filetable/filetabletest/main_test.go | 2 + pkg/cloud/userfile/main_test.go | 2 + pkg/jobs/BUILD.bazel | 1 - pkg/jobs/jobs_test.go | 18 ++++----- .../protectedts/ptstorage/BUILD.bazel | 3 +- .../protectedts/ptstorage/storage_test.go | 39 ++++++++++++------- 13 files changed, 85 insertions(+), 82 deletions(-) diff --git a/pkg/cli/BUILD.bazel b/pkg/cli/BUILD.bazel index a812a9b45e06..8c3c358c01c6 100644 --- a/pkg/cli/BUILD.bazel +++ b/pkg/cli/BUILD.bazel @@ -391,7 +391,6 @@ go_test( "//pkg/sql/catalog/descpb", "//pkg/sql/isql", "//pkg/sql/protoreflect", - "//pkg/sql/tests", "//pkg/storage", "//pkg/testutils", "//pkg/testutils/datapathutils", diff --git a/pkg/cli/zip_table_registry_test.go b/pkg/cli/zip_table_registry_test.go index 3718fca41f7f..3746dcc137e0 100644 --- a/pkg/cli/zip_table_registry_test.go +++ b/pkg/cli/zip_table_registry_test.go @@ -16,10 +16,10 @@ import ( "testing" "github.com/cockroachdb/cockroach/pkg/base" - "github.com/cockroachdb/cockroach/pkg/sql/tests" "github.com/cockroachdb/cockroach/pkg/testutils/serverutils" "github.com/cockroachdb/cockroach/pkg/testutils/sqlutils" "github.com/cockroachdb/cockroach/pkg/util/leaktest" + "github.com/cockroachdb/cockroach/pkg/util/log" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -159,15 +159,14 @@ func executeAllCustomQuerys( func TestCustomQuery(t *testing.T) { defer leaktest.AfterTest(t)() - ctx := context.Background() + defer log.Scope(t).Close(t) - params, _ := tests.CreateTestServerParams() cluster := serverutils.StartNewTestCluster(t, 3 /* numNodes */, base.TestClusterArgs{ - ServerArgs: params, + ServerArgs: base.TestServerArgs{}, }) + defer cluster.Stopper().Stop(context.Background()) testConn := cluster.ServerConn(0 /* idx */) sqlDB := sqlutils.MakeSQLRunner(testConn) - defer cluster.Stopper().Stop(ctx) executeAllCustomQuerys(t, sqlDB, zipInternalTablesPerCluster) executeAllCustomQuerys(t, sqlDB, zipInternalTablesPerNode) diff --git a/pkg/cli/zip_test.go b/pkg/cli/zip_test.go index d6d2f7223ea4..4e7eeed4cbcb 100644 --- a/pkg/cli/zip_test.go +++ b/pkg/cli/zip_test.go @@ -35,7 +35,6 @@ import ( "github.com/cockroachdb/cockroach/pkg/security/username" "github.com/cockroachdb/cockroach/pkg/server" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" - "github.com/cockroachdb/cockroach/pkg/sql/tests" "github.com/cockroachdb/cockroach/pkg/testutils" "github.com/cockroachdb/cockroach/pkg/testutils/datapathutils" "github.com/cockroachdb/cockroach/pkg/testutils/serverutils" @@ -218,10 +217,9 @@ func TestConcurrentZip(t *testing.T) { ctx := context.Background() // Three nodes. We want to see what `zip` thinks when one of the nodes is down. - params, _ := tests.CreateTestServerParams() - params.Insecure = true - tc := testcluster.StartTestCluster(t, 3, - base.TestClusterArgs{ServerArgs: params}) + tc := testcluster.StartTestCluster(t, 3, base.TestClusterArgs{ + ServerArgs: base.TestServerArgs{Insecure: true}, + }) defer tc.Stopper().Stop(ctx) // Zip it. We fake a CLI test context for this. @@ -327,14 +325,11 @@ func TestUnavailableZip(t *testing.T) { } // Make a 2-node cluster, with an option to make the first node unavailable. - params, _ := tests.CreateTestServerParams() - params.Insecure = true tc := testcluster.StartTestCluster(t, 2, base.TestClusterArgs{ ServerArgsPerNode: map[int]base.TestServerArgs{ 0: {Insecure: true, Knobs: base.TestingKnobs{Store: knobs}}, 1: {Insecure: true}, }, - ServerArgs: params, }) defer tc.Stopper().Stop(context.Background()) @@ -445,10 +440,9 @@ func TestPartialZip(t *testing.T) { ctx := context.Background() // Three nodes. We want to see what `zip` thinks when one of the nodes is down. - params, _ := tests.CreateTestServerParams() - params.Insecure = true - tc := testcluster.StartTestCluster(t, 3, - base.TestClusterArgs{ServerArgs: params}) + tc := testcluster.StartTestCluster(t, 3, base.TestClusterArgs{ + ServerArgs: base.TestServerArgs{Insecure: true}, + }) defer tc.Stopper().Stop(ctx) // Switch off the second node. @@ -538,9 +532,7 @@ func TestZipRetries(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) - params, _ := tests.CreateTestServerParams() - params.Insecure = true - s, _, _ := serverutils.StartServer(t, params) + s, _, _ := serverutils.StartServer(t, base.TestServerArgs{Insecure: true}) defer s.Stopper().Stop(context.Background()) dir, cleanupFn := testutils.TempDir(t) diff --git a/pkg/cloud/userfile/BUILD.bazel b/pkg/cloud/userfile/BUILD.bazel index 13f1e8e5bfc8..90f99a8200c4 100644 --- a/pkg/cloud/userfile/BUILD.bazel +++ b/pkg/cloud/userfile/BUILD.bazel @@ -32,10 +32,11 @@ go_test( "main_test.go", ], args = ["-test.timeout=295s"], - embed = [":userfile"], deps = [ + ":userfile", "//pkg/base", "//pkg/blobs", + "//pkg/ccl", "//pkg/cloud", "//pkg/cloud/cloudtestutils", "//pkg/security/securityassets", @@ -45,7 +46,6 @@ go_test( "//pkg/settings/cluster", "//pkg/sql/isql", "//pkg/sql/sem/tree", - "//pkg/sql/tests", "//pkg/testutils", "//pkg/testutils/serverutils", "//pkg/util/leaktest", diff --git a/pkg/cloud/userfile/file_table_storage_test.go b/pkg/cloud/userfile/file_table_storage_test.go index eac0d2f96cd9..08cca7399c01 100644 --- a/pkg/cloud/userfile/file_table_storage_test.go +++ b/pkg/cloud/userfile/file_table_storage_test.go @@ -7,7 +7,7 @@ // the Business Source License, use of this software will be governed // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. -package userfile +package userfile_test import ( "bytes" @@ -21,11 +21,11 @@ import ( "github.com/cockroachdb/cockroach/pkg/blobs" "github.com/cockroachdb/cockroach/pkg/cloud" "github.com/cockroachdb/cockroach/pkg/cloud/cloudtestutils" + "github.com/cockroachdb/cockroach/pkg/cloud/userfile" "github.com/cockroachdb/cockroach/pkg/security/username" "github.com/cockroachdb/cockroach/pkg/settings/cluster" "github.com/cockroachdb/cockroach/pkg/sql/isql" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" - "github.com/cockroachdb/cockroach/pkg/sql/tests" "github.com/cockroachdb/cockroach/pkg/testutils" "github.com/cockroachdb/cockroach/pkg/testutils/serverutils" "github.com/cockroachdb/cockroach/pkg/util/leaktest" @@ -40,14 +40,13 @@ func TestPutUserFileTable(t *testing.T) { qualifiedTableName := "defaultdb.public.user_file_table_test" filename := "path/to/file" - testSettings := cluster.MakeTestingClusterSettings() - ctx := context.Background() - params, _ := tests.CreateTestServerParams() - s, _, _ := serverutils.StartServer(t, params) - defer s.Stopper().Stop(ctx) + srv, _, _ := serverutils.StartServer(t, base.TestServerArgs{}) + defer srv.Stopper().Stop(ctx) + s := srv.TenantOrServer() + testSettings := s.ClusterSettings() - dest := MakeUserFileStorageURI(qualifiedTableName, filename) + dest := userfile.MakeUserFileStorageURI(qualifiedTableName, filename) db := s.InternalDB().(isql.DB) cloudtestutils.CheckExportStore(t, dest, false, username.RootUserName(), db, testSettings) @@ -56,7 +55,7 @@ func TestPutUserFileTable(t *testing.T) { username.RootUserName(), db, testSettings) t.Run("empty-qualified-table-name", func(t *testing.T) { - dest := MakeUserFileStorageURI("", filename) + dest := userfile.MakeUserFileStorageURI("", filename) cloudtestutils.CheckExportStore(t, dest, false, username.RootUserName(), db, testSettings) @@ -103,11 +102,11 @@ func TestUserScoping(t *testing.T) { filename := "path/to/file" ctx := context.Background() - params, _ := tests.CreateTestServerParams() - s, sqlDB, _ := serverutils.StartServer(t, params) - defer s.Stopper().Stop(ctx) + srv, sqlDB, _ := serverutils.StartServer(t, base.TestServerArgs{}) + defer srv.Stopper().Stop(ctx) + s := srv.TenantOrServer() - dest := MakeUserFileStorageURI(qualifiedTableName, "") + dest := userfile.MakeUserFileStorageURI(qualifiedTableName, "") db := s.InternalDB().(isql.DB) // Create two users and grant them all privileges on defaultdb. diff --git a/pkg/cloud/userfile/filetable/filetabletest/BUILD.bazel b/pkg/cloud/userfile/filetable/filetabletest/BUILD.bazel index 2b058932e340..ca502b6b17ec 100644 --- a/pkg/cloud/userfile/filetable/filetabletest/BUILD.bazel +++ b/pkg/cloud/userfile/filetable/filetabletest/BUILD.bazel @@ -9,6 +9,8 @@ go_test( ], args = ["-test.timeout=295s"], deps = [ + "//pkg/base", + "//pkg/ccl", "//pkg/cloud/userfile/filetable", "//pkg/kv", "//pkg/security/securityassets", @@ -16,7 +18,6 @@ go_test( "//pkg/security/username", "//pkg/server", "//pkg/sql/isql", - "//pkg/sql/tests", "//pkg/testutils", "//pkg/testutils/serverutils", "//pkg/util/ioctx", diff --git a/pkg/cloud/userfile/filetable/filetabletest/file_table_read_writer_test.go b/pkg/cloud/userfile/filetable/filetabletest/file_table_read_writer_test.go index 7ba49cb05ad1..6bdb8e582569 100644 --- a/pkg/cloud/userfile/filetable/filetabletest/file_table_read_writer_test.go +++ b/pkg/cloud/userfile/filetable/filetabletest/file_table_read_writer_test.go @@ -18,11 +18,11 @@ import ( "sort" "testing" + "github.com/cockroachdb/cockroach/pkg/base" "github.com/cockroachdb/cockroach/pkg/cloud/userfile/filetable" "github.com/cockroachdb/cockroach/pkg/kv" "github.com/cockroachdb/cockroach/pkg/security/username" "github.com/cockroachdb/cockroach/pkg/sql/isql" - "github.com/cockroachdb/cockroach/pkg/sql/tests" "github.com/cockroachdb/cockroach/pkg/testutils" "github.com/cockroachdb/cockroach/pkg/testutils/serverutils" "github.com/cockroachdb/cockroach/pkg/util/ioctx" @@ -104,9 +104,9 @@ func TestListAndDeleteFiles(t *testing.T) { defer log.Scope(t).Close(t) ctx := context.Background() - params, _ := tests.CreateTestServerParams() - s, _, kvDB := serverutils.StartServer(t, params) - defer s.Stopper().Stop(ctx) + srv, _, kvDB := serverutils.StartServer(t, base.TestServerArgs{}) + defer srv.Stopper().Stop(ctx) + s := srv.TenantOrServer() executor := filetable.MakeInternalFileToTableExecutor( s.InternalDB().(isql.DB), @@ -157,9 +157,9 @@ func TestReadWriteFile(t *testing.T) { defer log.Scope(t).Close(t) ctx := context.Background() - params, _ := tests.CreateTestServerParams() - s, sqlDB, kvDB := serverutils.StartServer(t, params) - defer s.Stopper().Stop(ctx) + srv, sqlDB, kvDB := serverutils.StartServer(t, base.TestServerArgs{}) + defer srv.Stopper().Stop(ctx) + s := srv.TenantOrServer() executor := filetable.MakeInternalFileToTableExecutor( s.InternalDB().(isql.DB), @@ -332,9 +332,9 @@ func TestUserGrants(t *testing.T) { defer log.Scope(t).Close(t) ctx := context.Background() - params, _ := tests.CreateTestServerParams() - s, sqlDB, kvDB := serverutils.StartServer(t, params) - defer s.Stopper().Stop(ctx) + srv, sqlDB, kvDB := serverutils.StartServer(t, base.TestServerArgs{}) + defer srv.Stopper().Stop(ctx) + s := srv.TenantOrServer() conn, err := sqlDB.Conn(ctx) require.NoError(t, err) @@ -412,9 +412,9 @@ func TestDifferentUserDisallowed(t *testing.T) { defer log.Scope(t).Close(t) ctx := context.Background() - params, _ := tests.CreateTestServerParams() - s, sqlDB, kvDB := serverutils.StartServer(t, params) - defer s.Stopper().Stop(ctx) + srv, sqlDB, kvDB := serverutils.StartServer(t, base.TestServerArgs{}) + defer srv.Stopper().Stop(ctx) + s := srv.TenantOrServer() conn, err := sqlDB.Conn(ctx) require.NoError(t, err) @@ -466,9 +466,9 @@ func TestDifferentRoleDisallowed(t *testing.T) { defer log.Scope(t).Close(t) ctx := context.Background() - params, _ := tests.CreateTestServerParams() - s, sqlDB, kvDB := serverutils.StartServer(t, params) - defer s.Stopper().Stop(ctx) + srv, sqlDB, kvDB := serverutils.StartServer(t, base.TestServerArgs{}) + defer srv.Stopper().Stop(ctx) + s := srv.TenantOrServer() conn, err := sqlDB.Conn(ctx) require.NoError(t, err) @@ -525,9 +525,9 @@ func TestDatabaseScope(t *testing.T) { defer log.Scope(t).Close(t) ctx := context.Background() - params, _ := tests.CreateTestServerParams() - s, sqlDB, kvDB := serverutils.StartServer(t, params) - defer s.Stopper().Stop(ctx) + srv, sqlDB, kvDB := serverutils.StartServer(t, base.TestServerArgs{}) + defer srv.Stopper().Stop(ctx) + s := srv.TenantOrServer() executor := filetable.MakeInternalFileToTableExecutor( s.InternalDB().(isql.DB), diff --git a/pkg/cloud/userfile/filetable/filetabletest/main_test.go b/pkg/cloud/userfile/filetable/filetabletest/main_test.go index 5f98f35a9ff9..5d1400f8c0b0 100644 --- a/pkg/cloud/userfile/filetable/filetabletest/main_test.go +++ b/pkg/cloud/userfile/filetable/filetabletest/main_test.go @@ -14,6 +14,7 @@ import ( "os" "testing" + "github.com/cockroachdb/cockroach/pkg/ccl" "github.com/cockroachdb/cockroach/pkg/security/securityassets" "github.com/cockroachdb/cockroach/pkg/security/securitytest" "github.com/cockroachdb/cockroach/pkg/server" @@ -27,5 +28,6 @@ func TestMain(m *testing.M) { securityassets.SetLoader(securitytest.EmbeddedAssets) randutil.SeedForTests() serverutils.InitTestServerFactory(server.TestServerFactory) + defer ccl.TestingEnableEnterprise()() os.Exit(m.Run()) } diff --git a/pkg/cloud/userfile/main_test.go b/pkg/cloud/userfile/main_test.go index 6aa41f16ea2a..22ee9658c06e 100644 --- a/pkg/cloud/userfile/main_test.go +++ b/pkg/cloud/userfile/main_test.go @@ -14,6 +14,7 @@ import ( "os" "testing" + "github.com/cockroachdb/cockroach/pkg/ccl" "github.com/cockroachdb/cockroach/pkg/security/securityassets" "github.com/cockroachdb/cockroach/pkg/security/securitytest" "github.com/cockroachdb/cockroach/pkg/server" @@ -27,5 +28,6 @@ func TestMain(m *testing.M) { securityassets.SetLoader(securitytest.EmbeddedAssets) randutil.SeedForTests() serverutils.InitTestServerFactory(server.TestServerFactory) + defer ccl.TestingEnableEnterprise()() os.Exit(m.Run()) } diff --git a/pkg/jobs/BUILD.bazel b/pkg/jobs/BUILD.bazel index 9b288826a91e..1cf8587a6d15 100644 --- a/pkg/jobs/BUILD.bazel +++ b/pkg/jobs/BUILD.bazel @@ -139,7 +139,6 @@ go_test( "//pkg/sql/sem/tree", "//pkg/sql/sessiondata", "//pkg/sql/sqlliveness", - "//pkg/sql/tests", "//pkg/testutils", "//pkg/testutils/jobutils", "//pkg/testutils/serverutils", diff --git a/pkg/jobs/jobs_test.go b/pkg/jobs/jobs_test.go index 4fbac3945117..ab46cbf836d0 100644 --- a/pkg/jobs/jobs_test.go +++ b/pkg/jobs/jobs_test.go @@ -43,7 +43,6 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/isql" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" "github.com/cockroachdb/cockroach/pkg/sql/sqlliveness" - "github.com/cockroachdb/cockroach/pkg/sql/tests" "github.com/cockroachdb/cockroach/pkg/testutils" "github.com/cockroachdb/cockroach/pkg/testutils/jobutils" "github.com/cockroachdb/cockroach/pkg/testutils/serverutils" @@ -1218,10 +1217,11 @@ func TestJobLifecycle(t *testing.T) { ctx := context.Background() - params, _ := tests.CreateTestServerParams() + var params base.TestServerArgs params.Knobs.JobsTestingKnobs = &jobs.TestingKnobs{DisableRegistryLifecycleManagent: true} - s, sqlDB, _ := serverutils.StartServer(t, params) - defer s.Stopper().Stop(ctx) + srv, sqlDB, _ := serverutils.StartServer(t, params) + defer srv.Stopper().Stop(ctx) + s := srv.TenantOrServer() registry := s.JobRegistry().(*jobs.Registry) @@ -1799,7 +1799,7 @@ func TestShowJobs(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) - params, _ := tests.CreateTestServerParams() + var params base.TestServerArgs params.Knobs.JobsTestingKnobs = jobs.NewTestingKnobsWithShortIntervals() s, rawSQLDB, _ := serverutils.StartServer(t, params) sqlDB := sqlutils.MakeSQLRunner(rawSQLDB) @@ -1951,7 +1951,7 @@ func TestShowAutomaticJobs(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) - params, _ := tests.CreateTestServerParams() + var params base.TestServerArgs params.Knobs.KeyVisualizer = &keyvisualizer.TestingKnobs{ SkipJobBootstrap: true, } @@ -1961,7 +1961,7 @@ func TestShowAutomaticJobs(t *testing.T) { params.Knobs.UpgradeManager = &upgradebase.TestingKnobs{DontUseJobs: true} s, rawSQLDB, _ := serverutils.StartServer(t, params) ctx := context.Background() - r := s.JobRegistry().(*jobs.Registry) + r := s.TenantOrServer().JobRegistry().(*jobs.Registry) sqlDB := sqlutils.MakeSQLRunner(rawSQLDB) defer s.Stopper().Stop(context.Background()) @@ -2081,7 +2081,7 @@ func TestShowJobsWithError(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) - params, _ := tests.CreateTestServerParams() + var params base.TestServerArgs params.Knobs.UpgradeManager = &upgradebase.TestingKnobs{ DontUseJobs: true, SkipJobMetricsPollingJobBootstrap: true, @@ -2109,7 +2109,7 @@ SELECT id, payload, progress FROM "".crdb_internal.system_jobs ORDER BY id DESC } // Create 3 rows from the valid row, one of which is corrupted. - createJob(context.Background(), t, s.JobRegistry().(*jobs.Registry), jobID+1, payload, progress) + createJob(context.Background(), t, s.TenantOrServer().JobRegistry().(*jobs.Registry), jobID+1, payload, progress) // Create the second row with a corrupted progress field. if _, err := sqlDB.Exec(` diff --git a/pkg/kv/kvserver/protectedts/ptstorage/BUILD.bazel b/pkg/kv/kvserver/protectedts/ptstorage/BUILD.bazel index e0378fdf9102..454e9ad38aee 100644 --- a/pkg/kv/kvserver/protectedts/ptstorage/BUILD.bazel +++ b/pkg/kv/kvserver/protectedts/ptstorage/BUILD.bazel @@ -40,6 +40,7 @@ go_test( shard_count = 16, deps = [ "//pkg/base", + "//pkg/ccl", "//pkg/keys", "//pkg/kv", "//pkg/kv/kvserver/protectedts", @@ -57,11 +58,11 @@ go_test( "//pkg/sql/isql", "//pkg/sql/sem/tree", "//pkg/sql/sessiondata", - "//pkg/sql/tests", "//pkg/testutils", "//pkg/testutils/serverutils", "//pkg/testutils/testcluster", "//pkg/util/hlc", + "//pkg/util/leaktest", "//pkg/util/log", "//pkg/util/log/severity", "//pkg/util/protoutil", diff --git a/pkg/kv/kvserver/protectedts/ptstorage/storage_test.go b/pkg/kv/kvserver/protectedts/ptstorage/storage_test.go index 482f5a1777ba..028aeec087cf 100644 --- a/pkg/kv/kvserver/protectedts/ptstorage/storage_test.go +++ b/pkg/kv/kvserver/protectedts/ptstorage/storage_test.go @@ -23,6 +23,7 @@ import ( "unsafe" "github.com/cockroachdb/cockroach/pkg/base" + "github.com/cockroachdb/cockroach/pkg/ccl" "github.com/cockroachdb/cockroach/pkg/keys" "github.com/cockroachdb/cockroach/pkg/kv" "github.com/cockroachdb/cockroach/pkg/kv/kvserver/protectedts" @@ -37,11 +38,11 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/isql" "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" "github.com/cockroachdb/cockroach/pkg/sql/sessiondata" - "github.com/cockroachdb/cockroach/pkg/sql/tests" "github.com/cockroachdb/cockroach/pkg/testutils" "github.com/cockroachdb/cockroach/pkg/testutils/serverutils" "github.com/cockroachdb/cockroach/pkg/testutils/testcluster" "github.com/cockroachdb/cockroach/pkg/util/hlc" + "github.com/cockroachdb/cockroach/pkg/util/leaktest" "github.com/cockroachdb/cockroach/pkg/util/log" "github.com/cockroachdb/cockroach/pkg/util/log/severity" "github.com/cockroachdb/cockroach/pkg/util/protoutil" @@ -63,6 +64,14 @@ func TestStorage(t *testing.T) { } } +func setMaxSpans(ctx context.Context, tCtx *testContext, value int64) { + // We could've opened up a connection to the system tenant and set the + // setting via SQL, but then we'd need to wait until it's propagated to the + // tenant (if we're running with secondary tenants). To avoid that we'll + // simply override the setting instead. + protectedts.MaxSpans.Override(ctx, &tCtx.tc.TenantOrServer(0).ClusterSettings().SV, value) +} + var testCases = []testCase{ { name: "Protect - simple positive", @@ -118,8 +127,7 @@ var testCases = []testCase{ // max_bytes or max_spans has been exceeded. _, err := tCtx.tc.ServerConn(0).Exec("SET CLUSTER SETTING kv.protectedts.max_bytes = $1", 0) require.NoError(t, err) - _, err = tCtx.tc.ServerConn(0).Exec("SET CLUSTER SETTING kv.protectedts.max_spans = $1", 0) - require.NoError(t, err) + setMaxSpans(ctx, tCtx, 0) }), funcOp(func(ctx context.Context, t *testing.T, tCtx *testContext) { rec := newRecord(tCtx, tCtx.tc.Server(0).Clock().Now(), "", nil, tableTarget(42), tableSpan(42)) @@ -136,8 +144,7 @@ var testCases = []testCase{ ops: []op{ protectOp{spans: tableSpans(42)}, funcOp(func(ctx context.Context, t *testing.T, tCtx *testContext) { - _, err := tCtx.tc.ServerConn(0).Exec("SET CLUSTER SETTING kv.protectedts.max_spans = $1", 3) - require.NoError(t, err) + setMaxSpans(ctx, tCtx, 3) }), protectOp{ metaType: "asdf", @@ -214,8 +221,7 @@ var testCases = []testCase{ ops: []op{ protectOp{spans: tableSpans(42)}, funcOp(func(ctx context.Context, t *testing.T, tCtx *testContext) { - _, err := tCtx.tc.ServerConn(0).Exec("SET CLUSTER SETTING kv.protectedts.max_spans = $1", 0) - require.NoError(t, err) + setMaxSpans(ctx, tCtx, 0) }), protectOp{ spans: func() []roachpb.Span { @@ -478,6 +484,7 @@ type testCase struct { } func (test testCase) run(t *testing.T) { + defer log.Scope(t).Close(t) ctx := context.Background() var params base.TestServerArgs @@ -489,7 +496,7 @@ func (test testCase) run(t *testing.T) { tc := testcluster.StartTestCluster(t, 1, base.TestClusterArgs{ServerArgs: params}) defer tc.Stopper().Stop(ctx) - s := tc.Server(0) + s := tc.Server(0).TenantOrServer() ptm := ptstorage.New(s.ClusterSettings(), ptsKnobs) tCtx := testContext{ pts: ptm, @@ -685,7 +692,7 @@ func TestCorruptData(t *testing.T) { scope := log.Scope(t) defer scope.Close(t) - params, _ := tests.CreateTestServerParams() + var params base.TestServerArgs params.Knobs.SpanConfig = &spanconfig.TestingKnobs{ManagerDisableJobCreation: true} tc := testcluster.StartTestCluster(t, 1, base.TestClusterArgs{ServerArgs: params}) defer tc.Stopper().Stop(ctx) @@ -702,7 +709,7 @@ func TestCorruptData(t *testing.T) { scope := log.Scope(t) defer scope.Close(t) - params, _ := tests.CreateTestServerParams() + var params base.TestServerArgs params.Knobs.SpanConfig = &spanconfig.TestingKnobs{ManagerDisableJobCreation: true} tc := testcluster.StartTestCluster(t, 1, base.TestClusterArgs{ServerArgs: params}) defer tc.Stopper().Stop(ctx) @@ -747,13 +754,15 @@ func TestCorruptData(t *testing.T) { // TestErrorsFromSQL ensures that errors from the underlying Executor // are properly transmitted back to the client. func TestErrorsFromSQL(t *testing.T) { - ctx := context.Background() - params, _ := tests.CreateTestServerParams() + defer leaktest.AfterTest(t)() + defer log.Scope(t).Close(t) + defer ccl.TestingEnableEnterprise()() - tc := testcluster.StartTestCluster(t, 1, base.TestClusterArgs{ServerArgs: params}) - defer tc.Stopper().Stop(ctx) + ctx := context.Background() + srv, _, _ := serverutils.StartServer(t, base.TestServerArgs{}) + defer srv.Stopper().Stop(ctx) + s := srv.TenantOrServer() - s := tc.Server(0) pts := ptstorage.New(s.ClusterSettings(), &protectedts.TestingKnobs{}) db := s.InternalDB().(isql.DB) errFunc := func(string) error { return errors.New("boom") }