-
Notifications
You must be signed in to change notification settings - Fork 0
/
locker_test.go
67 lines (64 loc) · 1.15 KB
/
locker_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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
* 测试文件
*
* @title distribute_lock_test.go
* @projectName distributeLock
* @author sauryniu
* @date 2022/10/31 11:17
*/
package distributelock
import (
"context"
"fmt"
"testing"
)
func TestNewDistributeLock(t *testing.T) {
type args struct {
serverAddr string
ttl int
}
type args2 struct {
key string
}
tests := []struct {
name string
args args
args2 []args2
want Locker
}{
{
name: "1",
args: args{
serverAddr: "10.1.30.79:12379",
ttl: 30,
},
args2: []args2{
{key: "111"},
{key: "222"},
{key: "333"},
{key: "444"},
{key: "555"},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
locker := NewLocker(tt.args.serverAddr, tt.args.ttl, EtcdLock)
for _, arg := range tt.args2 {
fmt.Println(arg.key)
unlocker, err := locker.Lock(context.Background(), arg.key)
if err != nil {
panic(err)
}
unlocker, err = locker.Lock(context.Background(), arg.key, WithTTL(3))
if err != nil {
fmt.Println(err)
continue
}
if err = unlocker(context.Background()); err != nil {
panic(err)
}
}
})
}
}