Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backupccl: adjust a test to run for secondary tenant codec too #104820

Merged
merged 1 commit into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pkg/ccl/backupccl/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,6 @@ go_test(
"//pkg/testutils/datapathutils",
"//pkg/testutils/distsqlutils",
"//pkg/testutils/jobutils",
"//pkg/testutils/keysutils",
"//pkg/testutils/serverutils",
"//pkg/testutils/skip",
"//pkg/testutils/sqlutils",
Expand Down
67 changes: 41 additions & 26 deletions pkg/ccl/backupccl/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ import (
"github.com/cockroachdb/cockroach/pkg/sql/stats"
"github.com/cockroachdb/cockroach/pkg/testutils"
"github.com/cockroachdb/cockroach/pkg/testutils/jobutils"
"github.com/cockroachdb/cockroach/pkg/testutils/keysutils"
"github.com/cockroachdb/cockroach/pkg/testutils/serverutils"
"github.com/cockroachdb/cockroach/pkg/testutils/skip"
"github.com/cockroachdb/cockroach/pkg/testutils/sqlutils"
Expand Down Expand Up @@ -6177,11 +6176,7 @@ func getMockTableDesc(
// methods.
func TestPublicIndexTableSpans(t *testing.T) {
defer leaktest.AfterTest(t)()
codec := keysutils.TestingSQLCodec
execCfg := &sql.ExecutorConfig{
Codec: codec,
}
unusedMap := make(map[tableAndIndex]bool)

testCases := []struct {
name string
tableID descpb.ID
Expand Down Expand Up @@ -6268,29 +6263,49 @@ func TestPublicIndexTableSpans(t *testing.T) {
},
}

for _, test := range testCases {
tableDesc := getMockTableDesc(test.tableID, test.pkIndex,
test.indexes, test.addingIndexes, test.droppingIndexes)
t.Run(fmt.Sprintf("%s:%s", "forEachPublicIndexTableSpan", test.name), func(t *testing.T) {
var spans []roachpb.Span
forEachPublicIndexTableSpan(tableDesc.TableDesc(), unusedMap, codec, func(sp roachpb.Span) {
spans = append(spans, sp)
})
var unmergedSpans []string
for _, span := range spans {
unmergedSpans = append(unmergedSpans, span.String())
for _, useSecondaryTenant := range []bool{false, true} {
name, codec := "system", keys.SystemSQLCodec
if useSecondaryTenant {
const tenantID = 42
name, codec = "secondary", keys.MakeSQLCodec(roachpb.MustMakeTenantID(tenantID))
for _, tc := range testCases {
for i, sp := range tc.expectedSpans {
tc.expectedSpans[i] = fmt.Sprintf("/Tenant/%d%s", tenantID, sp)
}
for i, sp := range tc.expectedMergedSpans {
tc.expectedMergedSpans[i] = fmt.Sprintf("/Tenant/%d%s", tenantID, sp)
}
}
require.Equal(t, test.expectedSpans, unmergedSpans)
})
}
execCfg := &sql.ExecutorConfig{Codec: codec}
unusedMap := make(map[tableAndIndex]bool)

t.Run(fmt.Sprintf("%s:%s", "spansForAllTableIndexes", test.name), func(t *testing.T) {
mergedSpans, err := spansForAllTableIndexes(execCfg, []catalog.TableDescriptor{tableDesc}, nil /* revs */)
require.NoError(t, err)
var mergedSpanStrings []string
for _, mSpan := range mergedSpans {
mergedSpanStrings = append(mergedSpanStrings, mSpan.String())
t.Run(name, func(t *testing.T) {
for _, test := range testCases {
tableDesc := getMockTableDesc(test.tableID, test.pkIndex,
test.indexes, test.addingIndexes, test.droppingIndexes)
t.Run(fmt.Sprintf("%s:%s", "forEachPublicIndexTableSpan", test.name), func(t *testing.T) {
var spans []roachpb.Span
forEachPublicIndexTableSpan(tableDesc.TableDesc(), unusedMap, codec, func(sp roachpb.Span) {
spans = append(spans, sp)
})
var unmergedSpans []string
for _, span := range spans {
unmergedSpans = append(unmergedSpans, span.String())
}
require.Equal(t, test.expectedSpans, unmergedSpans)
})

t.Run(fmt.Sprintf("%s:%s", "spansForAllTableIndexes", test.name), func(t *testing.T) {
mergedSpans, err := spansForAllTableIndexes(execCfg, []catalog.TableDescriptor{tableDesc}, nil /* revs */)
require.NoError(t, err)
var mergedSpanStrings []string
for _, mSpan := range mergedSpans {
mergedSpanStrings = append(mergedSpanStrings, mSpan.String())
}
require.Equal(t, test.expectedMergedSpans, mergedSpanStrings)
})
}
require.Equal(t, test.expectedMergedSpans, mergedSpanStrings)
})
}
}
Expand Down