Skip to content

Commit

Permalink
Add more test cases
Browse files Browse the repository at this point in the history
Signed-off-by: Bin Shi <[email protected]>
  • Loading branch information
binshi-bing committed Jun 18, 2023
1 parent 71f31d8 commit 4f6badb
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions pkg/utils/syncutil/lock_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package syncutil

import (
"fmt"
"math/rand"
"sync"
"testing"
Expand All @@ -39,7 +40,7 @@ func TestLockGroup(t *testing.T) {
re.LessOrEqual(len(group.entries), 16)
}

func TestLockGroupWithRemoveEntryOnUnlock(t *testing.T) {
func TestLockGroupConcurrencyWithRemoveEntryOnUnlock(t *testing.T) {
re := require.New(t)
group := NewLockGroup(WithRemoveEntryOnUnlock(true))
concurrency := 50
Expand All @@ -53,7 +54,26 @@ func TestLockGroupWithRemoveEntryOnUnlock(t *testing.T) {
}
wg.Wait()
// Check that size of the lock group is limited.
re.LessOrEqual(len(group.entries), 16)
re.Equal(len(group.entries), 0)
}

// Test range lock in a scenario with non-consecutive large key space. One of example is
// keyspace group split loads non-consecutive keyspace meta in batches and lock all loaded
// keyspace meta within a batch at the same time.
func TestLockGroupRangeLockWithRemoveEntryOnUnlock(t *testing.T) {
re := require.New(t)
group := NewLockGroup(WithRemoveEntryOnUnlock(true))
for i := 0; i < 1024; i++ {
fmt.Println("lock ", i)
group.Lock(uint32(i))
}
re.Equal(len(group.entries), 1024)
for i := 0; i < 1024; i++ {
fmt.Println("unlock ", i)
group.Unlock(uint32(i))
}
// Check that size of the lock group is limited.
re.Equal(len(group.entries), 0)
}

// mustSequentialUpdateSingle checks that for any given update, update is sequential.
Expand Down

0 comments on commit 4f6badb

Please sign in to comment.