diff --git a/pkg/base/test_server_args.go b/pkg/base/test_server_args.go index 9c5baea50bb5..4f0b4e2dcd63 100644 --- a/pkg/base/test_server_args.go +++ b/pkg/base/test_server_args.go @@ -263,4 +263,9 @@ type TestTenantArgs struct { // ExternalIODirConfig is used to initialize the same-named // field on the server.Config struct. ExternalIODirConfig ExternalIODirConfig + + // If set, this will be appended to the Postgres URL by functions that + // automatically open a connection to the server. That's equivalent to running + // SET DATABASE=foo, which works even if the database doesn't (yet) exist. + UseDatabase string } diff --git a/pkg/ccl/changefeedccl/changefeed_test.go b/pkg/ccl/changefeedccl/changefeed_test.go index fd9cd271b506..e92055285f85 100644 --- a/pkg/ccl/changefeedccl/changefeed_test.go +++ b/pkg/ccl/changefeedccl/changefeed_test.go @@ -215,15 +215,10 @@ func TestChangefeedTenants(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) - ctx := context.Background() - defer changefeedbase.TestingSetDefaultFlushFrequency(testSinkFlushFrequency)() - - kvServer, kvSQLdb, _ := serverutils.StartServer(t, base.TestServerArgs{ - ExternalIODirConfig: base.ExternalIODirConfig{ - DisableOutbound: true, - }, + kvServer, kvSQLdb, cleanup := startTestServer(t, func(args *base.TestServerArgs) { + args.ExternalIODirConfig.DisableOutbound = true }) - defer kvServer.Stopper().Stop(ctx) + defer cleanup() tenantArgs := base.TestTenantArgs{ // crdb_internal.create_tenant called by StartTenant @@ -234,27 +229,16 @@ func TestChangefeedTenants(t *testing.T) { ExternalIODirConfig: base.ExternalIODirConfig{ DisableOutbound: true, }, + UseDatabase: `d`, } tenantServer, tenantDB := serverutils.StartTenant(t, kvServer, tenantArgs) tenantSQL := sqlutils.MakeSQLRunner(tenantDB) - // TODO(ssd): Cleanup this shared setup code once the refactor - // in #64693 is setttled. - tenantSQL.Exec(t, `SET CLUSTER SETTING kv.rangefeed.enabled = true`) - tenantSQL.Exec(t, `SET CLUSTER SETTING kv.closed_timestamp.target_duration = '100ms'`) - tenantSQL.Exec(t, `SET CLUSTER SETTING changefeed.experimental_poll_interval = '10ms'`) - - // Database `d` is hardcoded in a number of places. Create it - // and create a new connection to that database. - tenantSQL.Exec(t, `CREATE DATABASE d`) - tenantSQL = sqlutils.MakeSQLRunner( - serverutils.OpenDBConn(t, - tenantServer.SQLAddr(), `d`, false /* insecure */, kvServer.Stopper())) - tenantSQL.Exec(t, `CREATE TABLE foo_in_tenant (pk INT PRIMARY KEY)`) + tenantSQL.Exec(t, serverSetupStatements) + tenantSQL.Exec(t, `CREATE TABLE foo_in_tenant (pk INT PRIMARY KEY)`) t.Run("changefeed on non-tenant table fails", func(t *testing.T) { kvSQL := sqlutils.MakeSQLRunner(kvSQLdb) - kvSQL.Exec(t, `CREATE DATABASE d`) kvSQL.Exec(t, `CREATE TABLE d.foo (pk INT PRIMARY KEY)`) tenantSQL.ExpectErr(t, `table "foo" does not exist`, diff --git a/pkg/ccl/changefeedccl/helpers_test.go b/pkg/ccl/changefeedccl/helpers_test.go index 3db7169f036a..85c3ba1bbb60 100644 --- a/pkg/ccl/changefeedccl/helpers_test.go +++ b/pkg/ccl/changefeedccl/helpers_test.go @@ -353,6 +353,7 @@ func sinklessTenantTestWithServerArgs( ExternalIODirConfig: base.ExternalIODirConfig{ DisableOutbound: true, }, + UseDatabase: `d`, } tenantServer, tenantDB := serverutils.StartTenant(t, kvServer, tenantArgs) @@ -361,10 +362,6 @@ func sinklessTenantTestWithServerArgs( _, err := tenantDB.ExecContext(ctx, serverSetupStatements) require.NoError(t, err) - // Database `d` is hardcoded in a number of - // places. Create a new connection to that database. - tenantDB = serverutils.OpenDBConn(t, tenantServer.SQLAddr(), `d`, false /* insecure */, kvServer.Stopper()) - sink, cleanup := sqlutils.PGUrl(t, tenantServer.SQLAddr(), t.Name(), url.User(security.RootUser)) defer cleanup() diff --git a/pkg/testutils/serverutils/test_server_shim.go b/pkg/testutils/serverutils/test_server_shim.go index 016c6748354f..d377082336d2 100644 --- a/pkg/testutils/serverutils/test_server_shim.go +++ b/pkg/testutils/serverutils/test_server_shim.go @@ -351,7 +351,7 @@ func StartTenant( } goDB := OpenDBConn( - t, tenant.SQLAddr(), "", false /* insecure */, stopper) + t, tenant.SQLAddr(), params.UseDatabase, false /* insecure */, stopper) return tenant, goDB }