mirror of
https://github.com/charlienet/go-mixed.git
synced 2025-07-18 08:32:40 +08:00
update
This commit is contained in:
@ -3,10 +3,15 @@ package locker
|
||||
import (
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
var sourcekey = "u-0001"
|
||||
|
||||
func TestTryLock(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
func TestSourceLocker(t *testing.T) {
|
||||
l := NewSourceLocker()
|
||||
|
||||
@ -27,6 +32,32 @@ func TestSourceLocker(t *testing.T) {
|
||||
|
||||
wg.Wait()
|
||||
t.Log("n:", n)
|
||||
t.Logf("%+v", l)
|
||||
}
|
||||
|
||||
func TestSourceTryLock(t *testing.T) {
|
||||
c := 5
|
||||
n := 0
|
||||
wg := new(sync.WaitGroup)
|
||||
wg.Add(c)
|
||||
|
||||
l := NewSourceLocker()
|
||||
|
||||
for i := 0; i < c; i++ {
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
if l.TryLock(sourcekey) {
|
||||
n++
|
||||
time.Sleep(time.Second)
|
||||
|
||||
l.Unlock(sourcekey)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
t.Log("n:", n)
|
||||
t.Logf("%+v", l)
|
||||
}
|
||||
|
||||
func BenchmarkSourceLocker(b *testing.B) {
|
||||
|
Reference in New Issue
Block a user