@@ -18,6 +18,9 @@ func TestPersistableChannelQueue(t *testing.T) {
18
18
handleChan := make (chan * testData )
19
19
handle := func (data ... Data ) {
20
20
for _ , datum := range data {
21
+ if datum == nil {
22
+ continue
23
+ }
21
24
testDatum := datum .(* testData )
22
25
handleChan <- testDatum
23
26
}
@@ -42,13 +45,26 @@ func TestPersistableChannelQueue(t *testing.T) {
42
45
}, & testData {})
43
46
assert .NoError (t , err )
44
47
48
+ readyForShutdown := make (chan struct {})
49
+ readyForTerminate := make (chan struct {})
50
+
45
51
go queue .Run (func (shutdown func ()) {
46
52
lock .Lock ()
47
53
defer lock .Unlock ()
54
+ select {
55
+ case <- readyForShutdown :
56
+ default :
57
+ close (readyForShutdown )
58
+ }
48
59
queueShutdown = append (queueShutdown , shutdown )
49
60
}, func (terminate func ()) {
50
61
lock .Lock ()
51
62
defer lock .Unlock ()
63
+ select {
64
+ case <- readyForTerminate :
65
+ default :
66
+ close (readyForTerminate )
67
+ }
52
68
queueTerminate = append (queueTerminate , terminate )
53
69
})
54
70
@@ -74,6 +90,7 @@ func TestPersistableChannelQueue(t *testing.T) {
74
90
err = queue .Push (test1 )
75
91
assert .Error (t , err )
76
92
93
+ <- readyForShutdown
77
94
// Now shutdown the queue
78
95
lock .Lock ()
79
96
callbacks := make ([]func (), len (queueShutdown ))
@@ -97,6 +114,7 @@ func TestPersistableChannelQueue(t *testing.T) {
97
114
}
98
115
99
116
// terminate the queue
117
+ <- readyForTerminate
100
118
lock .Lock ()
101
119
callbacks = make ([]func (), len (queueTerminate ))
102
120
copy (callbacks , queueTerminate )
@@ -123,13 +141,26 @@ func TestPersistableChannelQueue(t *testing.T) {
123
141
}, & testData {})
124
142
assert .NoError (t , err )
125
143
144
+ readyForShutdown = make (chan struct {})
145
+ readyForTerminate = make (chan struct {})
146
+
126
147
go queue .Run (func (shutdown func ()) {
127
148
lock .Lock ()
128
149
defer lock .Unlock ()
150
+ select {
151
+ case <- readyForShutdown :
152
+ default :
153
+ close (readyForShutdown )
154
+ }
129
155
queueShutdown = append (queueShutdown , shutdown )
130
156
}, func (terminate func ()) {
131
157
lock .Lock ()
132
158
defer lock .Unlock ()
159
+ select {
160
+ case <- readyForTerminate :
161
+ default :
162
+ close (readyForTerminate )
163
+ }
133
164
queueTerminate = append (queueTerminate , terminate )
134
165
})
135
166
@@ -141,13 +172,15 @@ func TestPersistableChannelQueue(t *testing.T) {
141
172
assert .Equal (t , test2 .TestString , result4 .TestString )
142
173
assert .Equal (t , test2 .TestInt , result4 .TestInt )
143
174
175
+ <- readyForShutdown
144
176
lock .Lock ()
145
177
callbacks = make ([]func (), len (queueShutdown ))
146
178
copy (callbacks , queueShutdown )
147
179
lock .Unlock ()
148
180
for _ , callback := range callbacks {
149
181
callback ()
150
182
}
183
+ <- readyForTerminate
151
184
lock .Lock ()
152
185
callbacks = make ([]func (), len (queueTerminate ))
153
186
copy (callbacks , queueTerminate )
0 commit comments