-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlock_test.go
46 lines (39 loc) · 988 Bytes
/
lock_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package xylock_test
import (
"testing"
"github.com/xybor-x/xycond"
"github.com/xybor-x/xylock"
)
func TestLock(t *testing.T) {
var tests = []*xylock.Lock{{}, nil}
for i := range tests {
xycond.ExpectNotPanic(func() {
tests[i].LockFunc(func() {})
tests[i].RLockFunc(func() any { return nil })
tests[i].TryLock()
}).Test(t)
}
}
func TestRWLock(t *testing.T) {
var tests = []*xylock.RWLock{{}, nil}
for i := range tests {
xycond.ExpectNotPanic(func() {
tests[i].WLockFunc(func() {})
tests[i].RLockFunc(func() any { return nil })
tests[i].RWLockFunc(func() any { return nil })
tests[i].TryLock()
tests[i].TryRLock()
tests[i].RLocker()
}).Test(t)
}
}
func TestSemaphore(t *testing.T) {
var tests = []*xylock.Semaphore{xylock.NewSemaphore(1), nil}
for i := range tests {
xycond.ExpectNotPanic(func() {
tests[i].AcquireFunc(1, func() {})
tests[i].RAcquireFunc(1, func() any { return nil })
tests[i].TryAcquire(1)
}).Test(t)
}
}