Skip to content

Commit

Permalink
changefeedccl: Shutdown tenant server prior to main server.
Browse files Browse the repository at this point in the history
`TestChangefeedTenants` would incorrectly skip the shutdown
of the tenant server.  This leads to spurious log error messages, and
results in slower execution speed.

Release Notes: None
  • Loading branch information
Yevgeniy Miretskiy committed Feb 1, 2022
1 parent 1cdee86 commit db2cec8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
25 changes: 7 additions & 18 deletions pkg/ccl/changefeedccl/changefeed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,28 +228,17 @@ func TestChangefeedTenants(t *testing.T) {
defer leaktest.AfterTest(t)()
defer log.Scope(t).Close(t)

kvServer, kvSQLdb, cleanup := startTestServer(t, feedTestOptions{argsFn: func(args *base.TestServerArgs) {
args.ExternalIODirConfig.DisableOutbound = true
}})
ts, tenantDB, cleanup := startTestTenant(t,
feedTestOptions{argsFn: func(args *base.TestServerArgs) {
args.ExternalIODirConfig.DisableOutbound = true
}})
defer cleanup()

tenantArgs := base.TestTenantArgs{
// crdb_internal.create_tenant called by StartTenant
TenantID: serverutils.TestTenantID(),
// Non-enterprise changefeeds are currently only
// disabled by setting DisableOutbound true
// everywhere.
ExternalIODirConfig: base.ExternalIODirConfig{
DisableOutbound: true,
},
UseDatabase: `d`,
}

tenantServer, tenantDB := serverutils.StartTenant(t, kvServer, tenantArgs)
kvServer, kvSQLdb := ts.(*testServerShim).kvServer, ts.(*testServerShim).kvSQL
tenantServer := ts.(*testServerShim).TestTenantInterface
tenantSQL := sqlutils.MakeSQLRunner(tenantDB)
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 TABLE d.foo (pk INT PRIMARY KEY)`)
Expand Down
2 changes: 2 additions & 0 deletions pkg/ccl/changefeedccl/helpers_tenant_shim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package changefeedccl

import (
"context"
"database/sql"
"net/http"

"github.com/cockroachdb/cockroach/pkg/base"
Expand Down Expand Up @@ -38,6 +39,7 @@ import (
type testServerShim struct {
serverutils.TestTenantInterface
kvServer serverutils.TestServerInterface
kvSQL *sql.DB
}

const unsupportedShimMethod = `
Expand Down
8 changes: 6 additions & 2 deletions pkg/ccl/changefeedccl/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ func startTestTenant(
) (serverutils.TestServerInterface, *gosql.DB, func()) {
ctx := context.Background()

kvServer, _, cleanupCluster := startTestFullServer(t, options)
kvServer, kvSQL, cleanupCluster := startTestFullServer(t, options)
knobs := base.TestingKnobs{
DistSQL: &execinfra.TestingKnobs{Changefeed: &TestingKnobs{}},
JobsTestingKnobs: jobs.NewTestingKnobsWithShortIntervals(),
Expand All @@ -433,7 +433,11 @@ func startTestTenant(
_, err := tenantDB.ExecContext(ctx, serverSetupStatements)
require.NoError(t, err)

server := &testServerShim{tenantServer, kvServer}
server := &testServerShim{
TestTenantInterface: tenantServer,
kvServer: kvServer,
kvSQL: kvSQL,
}
// Log so that it is clear if a failed test happened
// to run on a tenant.
t.Logf("Running test using tenant %s", tenantID)
Expand Down

0 comments on commit db2cec8

Please sign in to comment.