-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathlock_test.go
More file actions
43 lines (33 loc) · 822 Bytes
/
lock_test.go
File metadata and controls
43 lines (33 loc) · 822 Bytes
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
package trylock_test
import (
"testing"
"time"
"github.com/labring/aiproxy/core/common/trylock"
)
func TestMemLock(t *testing.T) {
if !trylock.MemLock("", time.Second) {
t.Error("Expected true, Got false")
}
if trylock.MemLock("", time.Second) {
t.Error("Expected false, Got true")
}
if trylock.MemLock("", time.Second) {
t.Error("Expected false, Got true")
}
time.Sleep(time.Second)
if !trylock.MemLock("", time.Second) {
t.Error("Expected true, Got false")
}
}
func TestMemLockPanicsOnTypeMismatch(t *testing.T) {
trylock.InjectMemLockValueForTest("panic-key", "bad")
t.Cleanup(func() {
trylock.ResetMemLockValueForTest("panic-key")
})
defer func() {
if recover() == nil {
t.Fatal("expected panic on mem lock type mismatch")
}
}()
trylock.MemLock("panic-key", time.Second)
}