Skip to content

Commit b64032f

Browse files
committed
consistently apply the same sort algorithm
1 parent 56a79ea commit b64032f

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

pkg/sql/rowcontainer/row_container_test.go

+15-2
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ import (
2828
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
2929
"github.com/cockroachdb/cockroach/pkg/sql/types"
3030
"github.com/cockroachdb/cockroach/pkg/storage"
31+
"github.com/cockroachdb/cockroach/pkg/util/cancelchecker"
3132
"github.com/cockroachdb/cockroach/pkg/util/encoding"
3233
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
3334
"github.com/cockroachdb/cockroach/pkg/util/mon"
3435
"github.com/cockroachdb/cockroach/pkg/util/randutil"
36+
utilsort "github.com/cockroachdb/cockroach/pkg/util/sort"
3537
"github.com/cockroachdb/cockroach/pkg/util/timeutil"
3638
"github.com/cockroachdb/errors"
3739
"github.com/stretchr/testify/require"
@@ -572,7 +574,7 @@ func TestDiskBackedIndexedRowContainer(t *testing.T) {
572574
}
573575

574576
sorter := rowsSorter{evalCtx: &evalCtx, rows: sortedRows, ordering: ordering}
575-
sort.Sort(&sorter)
577+
utilSort(&sorter, ctx)
576578
if sorter.err != nil {
577579
t.Fatal(sorter.err)
578580
}
@@ -667,7 +669,7 @@ func TestDiskBackedIndexedRowContainer(t *testing.T) {
667669
defer diskMonitor.Stop(ctx)
668670

669671
sorter := rowsSorter{evalCtx: &evalCtx, rows: sortedRows, ordering: ordering}
670-
sort.Sort(&sorter)
672+
utilSort(&sorter, ctx)
671673
if sorter.err != nil {
672674
t.Fatal(sorter.err)
673675
}
@@ -810,6 +812,17 @@ func TestDiskBackedIndexedRowContainer(t *testing.T) {
810812
})
811813
}
812814

815+
// Rows are sorted using an in-tree sort implementation that is the Go standard
816+
// library's sort with cancellation checking added. Go 1.19 introduced a new
817+
// sort algorithm which is also an unstable sort, but in a different way. It seems
818+
// like a bad choice to change the sorting algorithm in v22.1.x, so we instead
819+
// make the test use the same in-tree sort implementation.
820+
func utilSort(data sort.Interface, ctx context.Context) {
821+
var cancelChecker cancelchecker.CancelChecker
822+
cancelChecker.Reset(ctx)
823+
utilsort.Sort(data, &cancelChecker)
824+
}
825+
813826
// indexedRows are rows with the corresponding indices.
814827
type indexedRows struct {
815828
rows []IndexedRow

0 commit comments

Comments
 (0)