forked from mxenabled/go-workers2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathall_specs_test.go
72 lines (61 loc) · 1.33 KB
/
all_specs_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
68
69
70
71
72
package workers
import "context"
func setupTestOptions() (Options, error) {
return setupTestOptionsWithNamespace("")
}
func setupTestOptionsWithNamespace(namespace string) (Options, error) {
opts, err := processOptions(testOptionsWithNamespace(namespace))
if opts.client != nil {
opts.client.FlushDB(context.Background()).Result()
}
return opts, err
}
func testOptionsWithNamespace(namespace string) Options {
return Options{
ServerAddr: "localhost:6379",
ProcessID: "1",
Database: 15,
PoolSize: 1,
Namespace: namespace,
}
}
type callCounter struct {
count int
syncCh chan *Msg
ackSyncCh chan bool
}
func newCallCounter() *callCounter {
return &callCounter{
syncCh: make(chan *Msg),
ackSyncCh: make(chan bool),
}
}
func (j *callCounter) getOpt(m *Msg, opt string) bool {
if m == nil {
return false
}
return m.Args().GetIndex(0).Get(opt).MustBool()
}
func (j *callCounter) F(m *Msg) error {
j.count++
if m != nil {
if j.getOpt(m, "sync") {
j.syncCh <- m
<-j.ackSyncCh
}
m.ack = !j.getOpt(m, "noack")
}
return nil
}
func (j *callCounter) syncMsg() *Msg {
m, _ := NewMsg(`{"args": [{"sync": true}]}`)
return m
}
func (j *callCounter) msg() *Msg {
m, _ := NewMsg(`{"args": []}`)
return m
}
func (j *callCounter) noAckMsg() *Msg {
m, _ := NewMsg(`{"args": [{"noack": true}]}`)
return m
}