Skip to content

Commit 8ba7b9a

Browse files
committed
sql/tests: use newer btree in enum test
Informs: #144504 Release note: None
1 parent 67a692a commit 8ba7b9a

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

pkg/sql/tests/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,13 @@ go_test(
146146
"@com_github_cockroachdb_cockroach_go_v2//crdb/crdbpgxv5",
147147
"@com_github_cockroachdb_datadriven//:datadriven",
148148
"@com_github_cockroachdb_errors//:errors",
149+
"@com_github_google_btree//:btree",
149150
"@com_github_google_pprof//profile",
150151
"@com_github_jackc_pgx_v5//:pgx",
151152
"@com_github_jackc_pgx_v5//pgconn",
152153
"@com_github_kr_pretty//:pretty",
153154
"@com_github_lib_pq//:pq",
154155
"@com_github_petermattis_goid//:goid",
155-
"@com_github_raduberinde_btree//:btree",
156156
"@com_github_stretchr_testify//assert",
157157
"@com_github_stretchr_testify//require",
158158
"@org_golang_x_sync//errgroup",

pkg/sql/tests/enum_test.go

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,20 @@
66
package tests
77

88
import (
9+
"cmp"
910
"context"
1011
"fmt"
1112
"math/rand"
1213
"sort"
1314
"strings"
1415
"testing"
1516

16-
"github.com/RaduBerinde/btree" // TODO(#144504): switch to the newer btree
1717
"github.com/cockroachdb/cockroach/pkg/base"
1818
"github.com/cockroachdb/cockroach/pkg/testutils/serverutils"
1919
"github.com/cockroachdb/cockroach/pkg/testutils/sqlutils"
2020
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
2121
"github.com/cockroachdb/cockroach/pkg/util/log"
22+
"github.com/google/btree"
2223
"github.com/stretchr/testify/require"
2324
)
2425

@@ -46,17 +47,17 @@ func TestLargeEnums(t *testing.T) {
4647
// have to wait for lots of versions and it would take a very long time.
4748
var createEnumsQuery string
4849
{
49-
alreadyInserted := btree.New(8)
50+
alreadyInserted := btree.NewG[int](8, cmp.Less[int])
5051
next := func(n int) (next int, ok bool) {
51-
alreadyInserted.AscendGreaterOrEqual(intItem(n), func(i btree.Item) (wantMore bool) {
52-
next, ok = int(i.(intItem)), true
52+
alreadyInserted.AscendGreaterOrEqual(n, func(i int) (wantMore bool) {
53+
next, ok = i, true
5354
return false
5455
})
5556
return next, ok
5657
}
5758
prev := func(n int) (prev int, ok bool) {
58-
alreadyInserted.DescendLessOrEqual(intItem(n), func(i btree.Item) (wantMore bool) {
59-
prev, ok = int(i.(intItem)), true
59+
alreadyInserted.DescendLessOrEqual(n, func(i int) (wantMore bool) {
60+
prev, ok = i, true
6061
return false
6162
})
6263
return prev, ok
@@ -74,7 +75,7 @@ func TestLargeEnums(t *testing.T) {
7475
require.Truef(t, ok, "prev %v %v", n, order[:i])
7576
fmt.Fprintf(&buf, " AFTER '%d';\n", prev)
7677
}
77-
alreadyInserted.ReplaceOrInsert(intItem(n))
78+
alreadyInserted.ReplaceOrInsert(n)
7879
}
7980
buf.WriteString("COMMIT;")
8081
createEnumsQuery = buf.String()
@@ -101,12 +102,6 @@ func TestLargeEnums(t *testing.T) {
101102
require.Truef(t, sort.IntsAreSorted(read), "%v", read)
102103
}
103104

104-
type intItem int
105-
106-
func (i intItem) Less(o btree.Item) bool {
107-
return i < o.(intItem)
108-
}
109-
110105
// TestEnumPlaceholderWithAsOfSystemTime is a regression test for an edge case
111106
// with bind where we would not properly deal with leases involving types.
112107
func TestEnumPlaceholderWithAsOfSystemTime(t *testing.T) {

0 commit comments

Comments
 (0)