Fix keylock test
This commit is contained in:
parent
79d09955a2
commit
049a34e3fc
1 changed files with 26 additions and 0 deletions
|
@ -61,3 +61,29 @@ func BenchmarkKeyLock_DifferentKeys(b *testing.B) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BenchmarkKeyLock_NoBusyWait(b *testing.B) {
|
||||||
|
l := New()
|
||||||
|
|
||||||
|
lockedKey := []string{"locked"}
|
||||||
|
l.LockKeys(lockedKey, nil)
|
||||||
|
|
||||||
|
cancel := make(chan struct{})
|
||||||
|
defer close(cancel)
|
||||||
|
for i := 0; i < 10000; i++ {
|
||||||
|
go func() {
|
||||||
|
l.LockKeys(lockedKey, cancel)
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
b.ResetTimer()
|
||||||
|
|
||||||
|
openKey := []string{"a"}
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
canceled, unlock := l.LockKeys(openKey, nil)
|
||||||
|
if canceled {
|
||||||
|
b.Fatal("spurious lock fail")
|
||||||
|
}
|
||||||
|
unlock()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue