Skip to content

Commit b958152

Browse files
committed
sql/rowexec: enable tests under secondary tenants
Given the modifications in recent commits, this mostly required plumbing the right codec into `eval.Context`. Additionally, a few tests needed some extra adjustments for the tenant prefix present in the spans. Only `TestWriteResumeSpan` is still skipped since it wasn't immediately clear what's wrong there. Release note: None
1 parent 3a397eb commit b958152

18 files changed

+124
-77
lines changed

pkg/sql/rowexec/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ go_test(
164164
}),
165165
deps = [
166166
"//pkg/base",
167-
"//pkg/gossip",
168167
"//pkg/jobs",
169168
"//pkg/jobs/jobspb",
170169
"//pkg/keys",
@@ -173,6 +172,7 @@ go_test(
173172
"//pkg/kv/kvclient/rangecache",
174173
"//pkg/kv/kvpb",
175174
"//pkg/kv/kvserver",
175+
"//pkg/multitenant/tenantcapabilitiespb",
176176
"//pkg/roachpb",
177177
"//pkg/security/securityassets",
178178
"//pkg/security/securitytest",

pkg/sql/rowexec/aggregator_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,15 @@ func TestAggregator(t *testing.T) {
389389
}
390390

391391
ctx := context.Background()
392-
test := MakeProcessorTest(DefaultProcessorTestConfig())
392+
st := cluster.MakeTestingClusterSettings()
393+
evalCtx := eval.MakeTestingEvalContext(st)
394+
test := MakeProcessorTest(ProcessorTestConfig{
395+
FlowCtx: &execinfra.FlowCtx{
396+
Cfg: &execinfra.ServerConfig{Settings: st},
397+
EvalCtx: &evalCtx,
398+
Mon: evalCtx.TestingMon,
399+
},
400+
})
393401
defer test.Close(ctx)
394402
test.RunTestCases(ctx, t, testCases)
395403
}

pkg/sql/rowexec/backfiller_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ func TestWriteResumeSpan(t *testing.T) {
7575
},
7676
},
7777
},
78+
DefaultTestTenant: base.TestIsForStuffThatShouldWorkWithSecondaryTenantsButDoesntYet(156127),
7879
})
7980
defer srv.Stopper().Stop(ctx)
8081
s := srv.ApplicationLayer()

pkg/sql/rowexec/inverted_filterer_test.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/cockroachdb/cockroach/pkg/sql/execinfra"
1515
"github.com/cockroachdb/cockroach/pkg/sql/execinfrapb"
1616
"github.com/cockroachdb/cockroach/pkg/sql/inverted"
17+
"github.com/cockroachdb/cockroach/pkg/sql/sem/eval"
1718
"github.com/cockroachdb/cockroach/pkg/sql/types"
1819
"github.com/cockroachdb/cockroach/pkg/testutils/serverutils"
1920
"github.com/cockroachdb/cockroach/pkg/util/encoding"
@@ -120,14 +121,22 @@ func TestInvertedFilterer(t *testing.T) {
120121
}
121122
// Setup test environment.
122123
ctx := context.Background()
123-
server := serverutils.StartServerOnly(t, base.TestServerArgs{})
124-
defer server.Stopper().Stop(ctx)
125-
testConfig := DefaultProcessorTestConfig()
126-
diskMonitor := execinfra.NewTestDiskMonitor(ctx, testConfig.FlowCtx.Cfg.Settings)
124+
srv := serverutils.StartServerOnly(t, base.TestServerArgs{})
125+
defer srv.Stopper().Stop(ctx)
126+
s := srv.ApplicationLayer()
127+
st := s.ClusterSettings()
128+
evalCtx := eval.MakeTestingEvalContextWithCodec(s.Codec(), st)
129+
diskMonitor := execinfra.NewTestDiskMonitor(ctx, st)
127130
defer diskMonitor.Stop(ctx)
128-
testConfig.FlowCtx.DiskMonitor = diskMonitor
129-
testConfig.FlowCtx.Txn = kv.NewTxn(ctx, server.DB(), server.NodeID())
130-
test := MakeProcessorTest(testConfig)
131+
test := MakeProcessorTest(ProcessorTestConfig{
132+
FlowCtx: &execinfra.FlowCtx{
133+
Cfg: &execinfra.ServerConfig{Settings: st},
134+
EvalCtx: &evalCtx,
135+
Mon: evalCtx.TestingMon,
136+
DiskMonitor: diskMonitor,
137+
Txn: kv.NewTxn(ctx, s.DB(), srv.NodeID()),
138+
},
139+
})
131140
defer test.Close(ctx)
132141

133142
// Run test.

pkg/sql/rowexec/inverted_joiner_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212

1313
"github.com/cockroachdb/cockroach/pkg/base"
1414
"github.com/cockroachdb/cockroach/pkg/kv"
15-
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
1615
"github.com/cockroachdb/cockroach/pkg/sql/catalog"
1716
"github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb"
1817
"github.com/cockroachdb/cockroach/pkg/sql/catalog/desctestutils"
@@ -624,15 +623,15 @@ func TestInvertedJoiner(t *testing.T) {
624623
testCases[i] = initCommonFields(c)
625624
}
626625

627-
st := cluster.MakeTestingClusterSettings()
626+
st := s.ClusterSettings()
628627
tempEngine, _, err := storage.NewTempEngine(ctx, base.DefaultTestTempStorageConfig(st), nil /* statsCollector */)
629628
if err != nil {
630629
t.Fatal(err)
631630
}
632631
defer tempEngine.Close()
633632
diskMonitor := execinfra.NewTestDiskMonitor(ctx, st)
634633
defer diskMonitor.Stop(ctx)
635-
evalCtx := eval.MakeTestingEvalContext(st)
634+
evalCtx := eval.MakeTestingEvalContextWithCodec(s.Codec(), st)
636635
defer evalCtx.Stop(ctx)
637636
flowCtx := execinfra.FlowCtx{
638637
EvalCtx: &evalCtx,
@@ -764,13 +763,13 @@ func TestInvertedJoinerDrain(t *testing.T) {
764763
tracer := s.TracerI().(*tracing.Tracer)
765764
ctx, sp := tracer.StartSpanCtx(context.Background(), "test flow ctx", tracing.WithRecording(tracingpb.RecordingVerbose))
766765
defer sp.Finish()
767-
st := cluster.MakeTestingClusterSettings()
766+
st := s.ClusterSettings()
768767
tempEngine, _, err := storage.NewTempEngine(ctx, base.DefaultTestTempStorageConfig(st), nil /* statsCollector */)
769768
if err != nil {
770769
t.Fatal(err)
771770
}
772771
defer tempEngine.Close()
773-
evalCtx := eval.MakeTestingEvalContext(st)
772+
evalCtx := eval.MakeTestingEvalContextWithCodec(s.Codec(), st)
774773
defer evalCtx.Stop(context.Background())
775774
diskMonitor := execinfra.NewTestDiskMonitor(ctx, st)
776775
defer diskMonitor.Stop(ctx)

pkg/sql/rowexec/joinreader_blackbox_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,9 @@ func TestJoinReaderUsesBatchLimit(t *testing.T) {
100100
tableID := desc.TableDesc().ID
101101
sp, ok := rec.FindSpan("join reader")
102102
require.True(t, ok)
103-
require.Greater(t, tracing.CountLogMessages(sp, fmt.Sprintf("Scan /Table/%d", tableID)), 1)
103+
var tenantPrefix string
104+
if srv.StartedDefaultTestTenant() {
105+
tenantPrefix = fmt.Sprintf("/Tenant/%s", serverutils.TestTenantID())
106+
}
107+
require.Greater(t, tracing.CountLogMessages(sp, fmt.Sprintf("Scan %s/Table/%d", tenantPrefix, tableID)), 1)
104108
}

pkg/sql/rowexec/joinreader_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"github.com/cockroachdb/cockroach/pkg/base"
2121
"github.com/cockroachdb/cockroach/pkg/kv"
2222
"github.com/cockroachdb/cockroach/pkg/kv/kvclient/kvcoord"
23-
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
2423
"github.com/cockroachdb/cockroach/pkg/sql/catalog"
2524
"github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb"
2625
"github.com/cockroachdb/cockroach/pkg/sql/catalog/desctestutils"
@@ -1049,7 +1048,7 @@ func TestJoinReader(t *testing.T) {
10491048
expected: "[[0 1]]",
10501049
},
10511050
}
1052-
st := cluster.MakeTestingClusterSettings()
1051+
st := s.ClusterSettings()
10531052
tempEngine, _, err := storage.NewTempEngine(ctx, base.DefaultTestTempStorageConfig(st), nil /* statsCollector */)
10541053
if err != nil {
10551054
t.Fatal(err)
@@ -1079,7 +1078,7 @@ func TestJoinReader(t *testing.T) {
10791078
}
10801079
t.Run(fmt.Sprintf("%d/reqOrdering=%t/%s/smallBatch=%t/cont=%t",
10811080
i, reqOrdering, c.description, smallBatch, outputContinuation), func(t *testing.T) {
1082-
evalCtx := eval.MakeTestingEvalContext(st)
1081+
evalCtx := eval.MakeTestingEvalContextWithCodec(s.Codec(), st)
10831082
defer evalCtx.Stop(ctx)
10841083
flowCtx := execinfra.FlowCtx{
10851084
EvalCtx: &evalCtx,
@@ -1242,14 +1241,14 @@ CREATE TABLE test.t (a INT, s STRING, INDEX (a, s))`); err != nil {
12421241
}
12431242
td := desctestutils.TestingGetPublicTableDescriptor(kvDB, s.Codec(), "test", "t")
12441243

1245-
st := cluster.MakeTestingClusterSettings()
1244+
st := s.ClusterSettings()
12461245
tempEngine, _, err := storage.NewTempEngine(ctx, base.DefaultTestTempStorageConfig(st), nil /* statsCollector */)
12471246
if err != nil {
12481247
t.Fatal(err)
12491248
}
12501249
defer tempEngine.Close()
12511250

1252-
evalCtx := eval.MakeTestingEvalContext(st)
1251+
evalCtx := eval.MakeTestingEvalContextWithCodec(s.Codec(), st)
12531252
defer evalCtx.Stop(ctx)
12541253
diskMonitor := execinfra.NewTestDiskMonitor(ctx, st)
12551254
defer diskMonitor.Stop(ctx)
@@ -1360,7 +1359,7 @@ func TestJoinReaderDrain(t *testing.T) {
13601359
ctx, sp := tracer.StartSpanCtx(context.Background(), "test flow ctx", tracing.WithRecording(tracingpb.RecordingVerbose))
13611360
defer sp.Finish()
13621361

1363-
evalCtx := eval.MakeTestingEvalContext(st)
1362+
evalCtx := eval.MakeTestingEvalContextWithCodec(s.Codec(), st)
13641363
defer evalCtx.Stop(context.Background())
13651364
diskMonitor := execinfra.NewTestDiskMonitor(ctx, st)
13661365
defer diskMonitor.Stop(ctx)
@@ -1577,6 +1576,7 @@ func TestIndexJoiner(t *testing.T) {
15771576
txn := kv.NewTxn(context.Background(), s.DB(), srv.NodeID())
15781577
runProcessorTest(
15791578
t,
1579+
s.Codec(),
15801580
execinfrapb.ProcessorCoreUnion{JoinReader: &spec},
15811581
c.post,
15821582
types.TwoIntCols,
@@ -1660,7 +1660,7 @@ func benchmarkJoinReader(b *testing.B, bc JRBenchConfig) {
16601660
})
16611661
s = srv.ApplicationLayer()
16621662
st = s.ClusterSettings()
1663-
evalCtx = eval.MakeTestingEvalContext(st)
1663+
evalCtx = eval.MakeTestingEvalContextWithCodec(s.Codec(), st)
16641664
diskMonitor = execinfra.NewTestDiskMonitor(ctx, st)
16651665
flowCtx = execinfra.FlowCtx{
16661666
EvalCtx: &evalCtx,
@@ -1929,7 +1929,7 @@ func BenchmarkJoinReaderLookupStress(b *testing.B) {
19291929
})
19301930
s = srv.ApplicationLayer()
19311931
st = s.ClusterSettings()
1932-
evalCtx = eval.MakeTestingEvalContext(st)
1932+
evalCtx = eval.MakeTestingEvalContextWithCodec(s.Codec(), st)
19331933
diskMonitor = execinfra.NewTestDiskMonitor(ctx, st)
19341934
flowCtx = execinfra.FlowCtx{
19351935
EvalCtx: &evalCtx,

pkg/sql/rowexec/main_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"os"
1010
"testing"
1111

12-
"github.com/cockroachdb/cockroach/pkg/base"
1312
"github.com/cockroachdb/cockroach/pkg/security/securityassets"
1413
"github.com/cockroachdb/cockroach/pkg/security/securitytest"
1514
"github.com/cockroachdb/cockroach/pkg/server"
@@ -26,9 +25,5 @@ func TestMain(m *testing.M) {
2625
serverutils.InitTestServerFactory(server.TestServerFactory)
2726
serverutils.InitTestClusterFactory(testcluster.TestClusterFactory)
2827

29-
defer serverutils.TestingSetDefaultTenantSelectionOverride(
30-
base.TestIsForStuffThatShouldWorkWithSecondaryTenantsButDoesntYet(76378),
31-
)()
32-
3328
os.Exit(m.Run())
3429
}

pkg/sql/rowexec/processor_utils_test.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,11 @@ import (
1111
"strings"
1212
"testing"
1313

14-
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
1514
"github.com/cockroachdb/cockroach/pkg/sql/catalog/catenumpb"
1615
"github.com/cockroachdb/cockroach/pkg/sql/execinfra"
1716
"github.com/cockroachdb/cockroach/pkg/sql/execinfrapb"
1817
"github.com/cockroachdb/cockroach/pkg/sql/rowenc"
1918
"github.com/cockroachdb/cockroach/pkg/sql/rowenc/keyside"
20-
"github.com/cockroachdb/cockroach/pkg/sql/sem/eval"
2119
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
2220
"github.com/cockroachdb/cockroach/pkg/sql/types"
2321
"github.com/cockroachdb/cockroach/pkg/testutils/distsqlutils"
@@ -33,18 +31,6 @@ type ProcessorTestConfig struct {
3331
AfterTestCase func(p execinfra.Processor, inputs []execinfra.RowSource, output execinfra.RowReceiver)
3432
}
3533

36-
func DefaultProcessorTestConfig() ProcessorTestConfig {
37-
st := cluster.MakeTestingClusterSettings()
38-
evalCtx := eval.MakeTestingEvalContext(st)
39-
return ProcessorTestConfig{
40-
FlowCtx: &execinfra.FlowCtx{
41-
Cfg: &execinfra.ServerConfig{Settings: st},
42-
EvalCtx: &evalCtx,
43-
Mon: evalCtx.TestingMon,
44-
},
45-
}
46-
}
47-
4834
// ProcessorTestCaseRows is a number of rows of go values with an associated
4935
// schema that can be converted to sqlbase.EncDatumRows.
5036
type ProcessorTestCaseRows struct {

0 commit comments

Comments
 (0)