@@ -40,7 +40,10 @@ func TestUntil(t *testing.T) {
40
40
41
41
ch = make (chan struct {})
42
42
called := make (chan struct {})
43
+ wg := sync.WaitGroup {}
44
+ wg .Add (1 )
43
45
go func () {
46
+ defer wg .Done ()
44
47
Until (func () {
45
48
called <- struct {}{}
46
49
}, 0 , ch )
@@ -49,6 +52,7 @@ func TestUntil(t *testing.T) {
49
52
<- called
50
53
close (ch )
51
54
<- called
55
+ wg .Wait ()
52
56
}
53
57
54
58
func TestUntilWithContext (t * testing.T ) {
@@ -60,7 +64,10 @@ func TestUntilWithContext(t *testing.T) {
60
64
61
65
ctx , cancel = context .WithCancel (context .TODO ())
62
66
called := make (chan struct {})
67
+ wg := sync.WaitGroup {}
68
+ wg .Add (1 )
63
69
go func () {
70
+ defer wg .Done ()
64
71
UntilWithContext (ctx , func (context.Context ) {
65
72
called <- struct {}{}
66
73
}, 0 )
@@ -69,6 +76,7 @@ func TestUntilWithContext(t *testing.T) {
69
76
<- called
70
77
cancel ()
71
78
<- called
79
+ wg .Wait ()
72
80
}
73
81
74
82
func TestNonSlidingUntil (t * testing.T ) {
@@ -80,7 +88,10 @@ func TestNonSlidingUntil(t *testing.T) {
80
88
81
89
ch = make (chan struct {})
82
90
called := make (chan struct {})
91
+ wg := sync.WaitGroup {}
92
+ wg .Add (1 )
83
93
go func () {
94
+ defer wg .Done ()
84
95
NonSlidingUntil (func () {
85
96
called <- struct {}{}
86
97
}, 0 , ch )
@@ -89,6 +100,7 @@ func TestNonSlidingUntil(t *testing.T) {
89
100
<- called
90
101
close (ch )
91
102
<- called
103
+ wg .Wait ()
92
104
}
93
105
94
106
func TestNonSlidingUntilWithContext (t * testing.T ) {
@@ -100,7 +112,10 @@ func TestNonSlidingUntilWithContext(t *testing.T) {
100
112
101
113
ctx , cancel = context .WithCancel (context .TODO ())
102
114
called := make (chan struct {})
115
+ wg := sync.WaitGroup {}
116
+ wg .Add (1 )
103
117
go func () {
118
+ defer wg .Done ()
104
119
NonSlidingUntilWithContext (ctx , func (context.Context ) {
105
120
called <- struct {}{}
106
121
}, 0 )
@@ -109,6 +124,7 @@ func TestNonSlidingUntilWithContext(t *testing.T) {
109
124
<- called
110
125
cancel ()
111
126
<- called
127
+ wg .Wait ()
112
128
}
113
129
114
130
func TestUntilReturnsImmediately (t * testing.T ) {
@@ -138,7 +154,10 @@ func TestJitterUntil(t *testing.T) {
138
154
139
155
ch = make (chan struct {})
140
156
called := make (chan struct {})
157
+ wg := sync.WaitGroup {}
158
+ wg .Add (1 )
141
159
go func () {
160
+ defer wg .Done ()
142
161
JitterUntil (func () {
143
162
called <- struct {}{}
144
163
}, 0 , 1.0 , true , ch )
@@ -147,6 +166,7 @@ func TestJitterUntil(t *testing.T) {
147
166
<- called
148
167
close (ch )
149
168
<- called
169
+ wg .Wait ()
150
170
}
151
171
152
172
func TestJitterUntilWithContext (t * testing.T ) {
@@ -158,7 +178,10 @@ func TestJitterUntilWithContext(t *testing.T) {
158
178
159
179
ctx , cancel = context .WithCancel (context .TODO ())
160
180
called := make (chan struct {})
181
+ wg := sync.WaitGroup {}
182
+ wg .Add (1 )
161
183
go func () {
184
+ defer wg .Done ()
162
185
JitterUntilWithContext (ctx , func (context.Context ) {
163
186
called <- struct {}{}
164
187
}, 0 , 1.0 , true )
@@ -167,6 +190,7 @@ func TestJitterUntilWithContext(t *testing.T) {
167
190
<- called
168
191
cancel ()
169
192
<- called
193
+ wg .Wait ()
170
194
}
171
195
172
196
func TestJitterUntilReturnsImmediately (t * testing.T ) {
@@ -220,7 +244,10 @@ func TestJitterUntilNegativeFactor(t *testing.T) {
220
244
ch := make (chan struct {})
221
245
called := make (chan struct {})
222
246
received := make (chan struct {})
247
+ wg := sync.WaitGroup {}
248
+ wg .Add (1 )
223
249
go func () {
250
+ defer wg .Done ()
224
251
JitterUntil (func () {
225
252
called <- struct {}{}
226
253
<- received
@@ -238,6 +265,7 @@ func TestJitterUntilNegativeFactor(t *testing.T) {
238
265
if now .Add (3 * time .Second ).Before (time .Now ()) {
239
266
t .Errorf ("JitterUntil did not returned after predefined period with negative jitter factor when the stop chan was closed inside the func" )
240
267
}
268
+ wg .Wait ()
241
269
}
242
270
243
271
func TestExponentialBackoff (t * testing.T ) {
@@ -440,7 +468,10 @@ func TestPollForever(t *testing.T) {
440
468
errc := make (chan error , 1 )
441
469
done := make (chan struct {}, 1 )
442
470
complete := make (chan struct {})
471
+ wg := sync.WaitGroup {}
472
+ wg .Add (1 )
443
473
go func () {
474
+ defer wg .Done ()
444
475
f := ConditionFunc (func () (bool , error ) {
445
476
ch <- struct {}{}
446
477
select {
@@ -479,7 +510,9 @@ func TestPollForever(t *testing.T) {
479
510
480
511
// at most one poll notification should be sent once we return from the condition
481
512
done <- struct {}{}
513
+ wg .Add (1 )
482
514
go func () {
515
+ defer wg .Done ()
483
516
for i := 0 ; i < 2 ; i ++ {
484
517
_ , open := <- ch
485
518
if ! open {
@@ -493,6 +526,7 @@ func TestPollForever(t *testing.T) {
493
526
if len (errc ) != 0 {
494
527
t .Fatal (<- errc )
495
528
}
529
+ wg .Wait ()
496
530
}
497
531
498
532
func Test_waitFor (t * testing.T ) {
@@ -631,8 +665,10 @@ func TestPollUntil(t *testing.T) {
631
665
stopCh := make (chan struct {})
632
666
called := make (chan bool )
633
667
pollDone := make (chan struct {})
634
-
668
+ wg := sync.WaitGroup {}
669
+ wg .Add (1 )
635
670
go func () {
671
+ defer wg .Done ()
636
672
PollUntil (time .Microsecond , ConditionFunc (func () (bool , error ) {
637
673
called <- true
638
674
return false , nil
@@ -655,6 +691,7 @@ func TestPollUntil(t *testing.T) {
655
691
// make sure we finished the poll
656
692
<- pollDone
657
693
close (called )
694
+ wg .Wait ()
658
695
}
659
696
660
697
func TestBackoff_Step (t * testing.T ) {
0 commit comments