Skip to content

Commit

Permalink
use global param
Browse files Browse the repository at this point in the history
Signed-off-by: okJiang <[email protected]>
  • Loading branch information
okJiang committed Jul 11, 2024
1 parent d4f4a8e commit 865e7e7
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions pkg/core/region_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1147,22 +1147,25 @@ func TestCntRefAfterResetRegionCache(t *testing.T) {
func TestScanRegion(t *testing.T) {
re := require.New(t)
tree := newRegionTree()
scanError := func(startKey, endKey []byte, limit int) ([]*RegionInfo, error) {
regions, err := scanRegion(tree, &KeyRange{StartKey: startKey, EndKey: endKey}, limit)
var (
regions []*RegionInfo
err error
)
scanError := func(startKey, endKey []byte, limit int) []*RegionInfo {
regions, err = scanRegion(tree, &KeyRange{StartKey: startKey, EndKey: endKey}, limit)
re.Error(err)
return regions, err
return regions
}
scanNoError := func(startKey, endKey []byte, limit int) []*RegionInfo {
regions, err := scanRegion(tree, &KeyRange{StartKey: startKey, EndKey: endKey}, limit)
regions, err = scanRegion(tree, &KeyRange{StartKey: startKey, EndKey: endKey}, limit)
re.NoError(err)
return regions
}
// region1
// [a, b)
updateNewItem(tree, NewTestRegionInfo(1, 1, []byte("a"), []byte("b")))
re.Len(scanNoError([]byte("a"), []byte("b"), 0), 1)
regions, _ := scanError([]byte("a"), []byte("c"), 0)
re.Len(regions, 1)
re.Len(scanError([]byte("a"), []byte("c"), 0), 1)
re.Len(scanNoError([]byte("a"), []byte("c"), 1), 1)

// region1 | region2
Expand All @@ -1174,25 +1177,21 @@ func TestScanRegion(t *testing.T) {
// region1 | region2 | region3
// [a, b) | [b, c) | [d, f)
updateNewItem(tree, NewTestRegionInfo(3, 1, []byte("d"), []byte("f")))
regions, _ = scanError([]byte("a"), []byte("e"), 0)
re.Len(regions, 3)
regions, _ = scanError([]byte("c"), []byte("e"), 0)
re.Len(regions, 1)
re.Len(scanError([]byte("a"), []byte("e"), 0), 3)
re.Len(scanError([]byte("c"), []byte("e"), 0), 1)
re.Equal(uint64(3), regions[0].GetID())

// region1 | region2 | region3 | region4
// [a, b) | [b, c) | [d, f) | [f, i)
updateNewItem(tree, NewTestRegionInfo(4, 1, []byte("f"), []byte("i")))
regions, _ = scanError([]byte("c"), []byte("g"), 0)
re.Len(regions, 2)
re.Len(scanError([]byte("c"), []byte("g"), 0), 2)
re.Equal(uint64(3), regions[0].GetID())
re.Equal(uint64(4), regions[1].GetID())

regions = scanNoError([]byte("g"), []byte("h"), 0)
re.Len(regions, 1)
re.Len(scanNoError([]byte("g"), []byte("h"), 0), 1)
re.Equal(uint64(4), regions[0].GetID())
// test multil error and error type
regions, err := scanError([]byte(string('a'-1)), []byte("g"), 0)
scanError([]byte(string('a'-1)), []byte("g"), 0)
multiErr := multierr.Errors(err)
re.Len(multiErr, 2)
re.True(errs.ErrRegionNotAdjacent.Equal(multiErr[0]))
Expand All @@ -1204,7 +1203,7 @@ func TestScanRegion(t *testing.T) {
// test boundless
re.Len(scanNoError([]byte("m"), nil, 0), 1)
// test errLimit
_, err = scanError([]byte(string('a'-1)), []byte("m"), 0)
scanError([]byte(string('a'-1)), []byte("m"), 0)
multiErr = multierr.Errors(err)
re.Len(multiErr, 3)
}

0 comments on commit 865e7e7

Please sign in to comment.