fix: add inmemory lock test for PR#14555 (#14570)

Co-authored-by: QIU Jian <qiujian@yunionyun.com>
This commit is contained in:
Jian Qiu
2022-07-08 21:54:35 +08:00
committed by GitHub
co-authored by QIU Jian
parent 532922d98a
commit 07997efbaa
@@ -15,7 +15,10 @@
package lockman
import (
"context"
"math/rand"
"testing"
"time"
)
func TestInMemoryLockManager(t *testing.T) {
@@ -29,3 +32,27 @@ func TestInMemoryLockManager(t *testing.T) {
}
testLockManager(t, cfg)
}
func TestRunManu(t *testing.T) {
rand.Seed(100)
lockman := NewInMemoryLockManager()
counter := 0
MAX := 512
for i := 0; i < MAX; i++ {
go func() {
ctx := context.Background()
now := time.Now()
ms := now.UnixMilli()
ctx = context.WithValue(ctx, "Time", ms)
lockman.LockKey(ctx, "test")
defer lockman.UnlockKey(ctx, "test")
counter++
time.Sleep(1 + time.Duration(rand.Intn(50))*time.Millisecond)
t.Logf("counter: %d", counter)
}()
}
for counter < MAX {
time.Sleep(1)
}
t.Logf("complete")
}