Skip to content

Commit

Permalink
storage: remove test dependency to sql/catalog/bootstrap
Browse files Browse the repository at this point in the history
Previously, tests in `pkg/storage` depended on `sql/catalog/bootstrap`.
This was inadequate/weird because `storage` is a much lower layer in the
architectural stack. It will also help prevent dependency cycles in
other PRs when we introduce depencies (see #82172 if interested).

Release note: None
  • Loading branch information
Xiang-Gu committed Jul 1, 2022
1 parent d324df1 commit 6ba0ac6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
1 change: 1 addition & 0 deletions pkg/storage/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ go_test(
"disk_map_test.go",
"engine_key_test.go",
"engine_test.go",
"external_helpers_test.go",
"intent_interleaving_iter_test.go",
"intent_reader_writer_test.go",
"main_test.go",
Expand Down
21 changes: 21 additions & 0 deletions pkg/storage/external_helpers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2022 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// 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 storage_test

import (
"github.com/cockroachdb/cockroach/pkg/sql/catalog/bootstrap"
"github.com/cockroachdb/cockroach/pkg/storage"
)

func init() {
storage.TestingUserDescID = bootstrap.TestingUserDescID
storage.TestingUserTableDataMin = bootstrap.TestingUserTableDataMin
}
13 changes: 9 additions & 4 deletions pkg/storage/mvcc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/cockroachdb/cockroach/pkg/keys"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/bootstrap"
"github.com/cockroachdb/cockroach/pkg/storage/enginepb"
"github.com/cockroachdb/cockroach/pkg/testutils"
"github.com/cockroachdb/cockroach/pkg/testutils/skip"
Expand Down Expand Up @@ -4374,13 +4373,16 @@ func TestFindSplitKey(t *testing.T) {
}
}

// Injected via `external_helpers_test.go`.
var TestingUserDescID func(offset uint32) uint32

// TestFindValidSplitKeys verifies split keys are located such that
// they avoid splits through invalid key ranges.
func TestFindValidSplitKeys(t *testing.T) {
defer leaktest.AfterTest(t)()
defer log.Scope(t).Close(t)

userID := bootstrap.TestingUserDescID(0)
userID := TestingUserDescID(0)
// Manually creates rows corresponding to the schema:
// CREATE TABLE t (id1 STRING, id2 STRING, ... PRIMARY KEY (id1, id2, ...))
addTablePrefix := func(prefix roachpb.Key, id uint32, rowVals ...string) roachpb.Key {
Expand Down Expand Up @@ -4574,7 +4576,7 @@ func TestFindValidSplitKeys(t *testing.T) {
addColFam(tablePrefix(userID, "b"), 1),
addColFam(tablePrefix(userID, "c"), 1),
},
rangeStart: keys.SystemSQLCodec.TablePrefix(bootstrap.TestingUserDescID(0)),
rangeStart: keys.SystemSQLCodec.TablePrefix(TestingUserDescID(0)),
expSplit: tablePrefix(userID, "b"),
expError: false,
},
Expand Down Expand Up @@ -5014,6 +5016,9 @@ func (it *seekLTTrackingIterator) SeekLT(k MVCCKey) {
it.MVCCIterator.SeekLT(k)
}

// Injected via `external_helpers_test.go`.
var TestingUserTableDataMin func() roachpb.Key

// TestMVCCGarbageCollectUsesSeekLTAppropriately ensures that the garbage
// collection only utilizes SeekLT if there are enough undeleted versions.
func TestMVCCGarbageCollectUsesSeekLTAppropriately(t *testing.T) {
Expand All @@ -5037,7 +5042,7 @@ func TestMVCCGarbageCollectUsesSeekLTAppropriately(t *testing.T) {
batch := engine.NewBatch()
defer batch.Close()
it := batch.NewMVCCIterator(MVCCKeyAndIntentsIterKind, IterOptions{
UpperBound: bootstrap.TestingUserTableDataMin(),
UpperBound: TestingUserTableDataMin(),
LowerBound: keys.MaxKey,
})
defer it.Close()
Expand Down

0 comments on commit 6ba0ac6

Please sign in to comment.