Rework soak test to error on unlock failure
This commit is contained in:
parent
b0f7e273e8
commit
01ebdd27f2
|
@ -77,8 +77,8 @@ func TestBackendLocksSoak(t *testing.T) {
|
||||||
testACC(t)
|
testACC(t)
|
||||||
defer cleanupK8sResources(t)
|
defer cleanupK8sResources(t)
|
||||||
|
|
||||||
clientCount := 1000
|
clientCount := 100
|
||||||
lockCount := 0
|
lockAttempts := 100
|
||||||
|
|
||||||
lockers := []statemgr.Locker{}
|
lockers := []statemgr.Locker{}
|
||||||
for i := 0; i < clientCount; i++ {
|
for i := 0; i < clientCount; i++ {
|
||||||
|
@ -97,30 +97,31 @@ func TestBackendLocksSoak(t *testing.T) {
|
||||||
wg := sync.WaitGroup{}
|
wg := sync.WaitGroup{}
|
||||||
for i, l := range lockers {
|
for i, l := range lockers {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func(locker statemgr.Locker, i int) {
|
go func(locker statemgr.Locker, n int) {
|
||||||
r := rand.Intn(10)
|
defer wg.Done()
|
||||||
time.Sleep(time.Duration(r) * time.Microsecond)
|
|
||||||
li := state.NewLockInfo()
|
li := state.NewLockInfo()
|
||||||
li.Operation = "test"
|
li.Operation = "test"
|
||||||
li.Who = fmt.Sprintf("client-%v", i)
|
li.Who = fmt.Sprintf("client-%v", n)
|
||||||
_, err := locker.Lock(li)
|
|
||||||
if err == nil {
|
for i := 0; i < lockAttempts; i++ {
|
||||||
t.Logf("[INFO] Client %v got the lock\r\n", i)
|
id, err := locker.Lock(li)
|
||||||
lockCount++
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// hold onto the lock for a little bit
|
||||||
|
time.Sleep(time.Duration(rand.Intn(10)) * time.Microsecond)
|
||||||
|
|
||||||
|
err = locker.Unlock(id)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to unlock: %v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
wg.Done()
|
|
||||||
}(l, i)
|
}(l, i)
|
||||||
}
|
}
|
||||||
|
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
||||||
if lockCount > 1 {
|
|
||||||
t.Fatalf("multiple backend clients were able to acquire a lock, count: %v", lockCount)
|
|
||||||
}
|
|
||||||
|
|
||||||
if lockCount == 0 {
|
|
||||||
t.Fatal("no clients were able to acquire a lock")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func cleanupK8sResources(t *testing.T) {
|
func cleanupK8sResources(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue