-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtracker_test.go
94 lines (76 loc) · 1.24 KB
/
tracker_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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package tracker_test
import (
"testing"
"time"
"github.com/s00500/tracker"
)
func TestTracker(t *testing.T) {
trk := tracker.Root()
trk.Go(func(tkr tracker.Tracker) {
someFunc(t, trk)
})
trk.Go(func(tkr tracker.Tracker) {
someFunc(t, trk)
})
trk.Go(func(tkr tracker.Tracker) {
someFunc(t, trk)
})
t.Log("Gonna wait for first")
trk.CancelAndWait()
t.Log("Done")
trk.CancelAndWait()
t.Log("Done2")
}
func TestEmptyTracker(t *testing.T) {
trk := tracker.Tracker{}
select {
case <-trk.Done():
return
}
t.Fail()
}
func someFunc(t *testing.T, trk tracker.Tracker) {
subTrk := trk.NewSubGroup()
// readloop
subTrk.Go(func(tkr tracker.Tracker) {
for {
select {
case <-tkr.Done():
t.Log("read done")
return
}
}
})
// Writeloop
subTrk.Go(func(tkr tracker.Tracker) {
for {
select {
case <-tkr.Done():
t.Log("write done")
return
}
}
})
select {
case <-time.Tick(time.Second * 5):
case <-trk.Done():
return
}
time.Sleep(time.Second * 5)
}
func TestSubTrackers(t *testing.T) {
some := struct {
trk tracker.Tracker
}{}
trk := tracker.Root()
sub := trk.NewSubGroup()
if !trk.IsRoot() {
t.Fail()
}
if sub.IsRoot() {
t.Fail()
}
if !some.trk.IsRoot() {
t.Fail()
}
}