goProject/trunk/goutil/syncUtil/rwLockerUtil_test.go

28 lines
640 B
Go
Raw Permalink Normal View History

2025-01-06 16:01:02 +08:00
package syncUtil
import (
"fmt"
"testing"
)
var (
rwLockerUtilObj = NewRWLockerUtil()
)
func RWLockerUtil_TestGetLock(t *testing.T) {
count := 100
for i := 1; i <= count; i++ {
rwLockerUtilObj.GetLock(fmt.Sprintf("%d", i))
if lockerCount := len(rwLockerUtilObj.lockerMap); lockerCount != i {
t.Errorf("(GetLock)Expected %d locker, but now got: %d", count, lockerCount)
}
}
for i := count; i > 0; i-- {
rwLockerUtilObj.ReleaseLock(fmt.Sprintf("%d", i))
if lockerCount := len(rwLockerUtilObj.lockerMap); lockerCount != i-1 {
t.Errorf("(ReleaseLock)Expected %d locker, but now got: %d", count, lockerCount)
}
}
}