-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtools_test.go
More file actions
93 lines (72 loc) · 1.48 KB
/
tools_test.go
File metadata and controls
93 lines (72 loc) · 1.48 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package waitprocess
import (
"context"
"sync/atomic"
"time"
)
type teststate struct {
state int32
}
func (t *teststate) add() {
atomic.AddInt32(&t.state, 1)
}
func (t *teststate) getstate() int {
return int(atomic.LoadInt32(&t.state))
}
type testprocess struct {
ch chan struct{}
runCount int32
stopCount int32
stopped int32
}
func withTestprocess() *testprocess {
return &testprocess{
ch: make(chan struct{}),
}
}
func (tp *testprocess) getRunCount() int {
return int(atomic.LoadInt32(&tp.runCount))
}
func (tp *testprocess) getStopCount() int {
return int(atomic.LoadInt32(&tp.stopCount))
}
func (tp *testprocess) Run() error {
atomic.AddInt32(&tp.runCount, 1)
<-tp.ch
return nil
}
func (tp *testprocess) Stop() {
atomic.AddInt32(&tp.stopCount, 1)
if ok := atomic.CompareAndSwapInt32(&tp.stopped, 0, 1); ok {
close(tp.ch)
}
}
func (tp *testprocess) SetContext(_ context.Context) {
}
type errprocess struct {
err error
}
func withErrprocess(err error) *errprocess {
return &errprocess{err}
}
func (ep *errprocess) Run() error {
return ep.err
}
func (ep *errprocess) Stop() {
}
func (ep *errprocess) SetContext(_ context.Context) {
}
type sleepprocess struct {
duration time.Duration
}
func withSleepprocess(duration time.Duration) *sleepprocess {
return &sleepprocess{duration}
}
func (tp *sleepprocess) Run() error {
time.Sleep(tp.duration)
return nil
}
func (tp *sleepprocess) Stop() {
}
func (tp *sleepprocess) SetContext(_ context.Context) {
}