@@ -40,7 +40,10 @@ func TestUntil(t *testing.T) {
4040
4141 ch = make (chan struct {})
4242 called := make (chan struct {})
43+ wg := sync.WaitGroup {}
44+ wg .Add (1 )
4345 go func () {
46+ defer wg .Done ()
4447 Until (func () {
4548 called <- struct {}{}
4649 }, 0 , ch )
@@ -49,6 +52,7 @@ func TestUntil(t *testing.T) {
4952 <- called
5053 close (ch )
5154 <- called
55+ wg .Wait ()
5256}
5357
5458func TestUntilWithContext (t * testing.T ) {
@@ -60,7 +64,10 @@ func TestUntilWithContext(t *testing.T) {
6064
6165 ctx , cancel = context .WithCancel (context .TODO ())
6266 called := make (chan struct {})
67+ wg := sync.WaitGroup {}
68+ wg .Add (1 )
6369 go func () {
70+ defer wg .Done ()
6471 UntilWithContext (ctx , func (context.Context ) {
6572 called <- struct {}{}
6673 }, 0 )
@@ -69,6 +76,7 @@ func TestUntilWithContext(t *testing.T) {
6976 <- called
7077 cancel ()
7178 <- called
79+ wg .Wait ()
7280}
7381
7482func TestNonSlidingUntil (t * testing.T ) {
@@ -80,7 +88,10 @@ func TestNonSlidingUntil(t *testing.T) {
8088
8189 ch = make (chan struct {})
8290 called := make (chan struct {})
91+ wg := sync.WaitGroup {}
92+ wg .Add (1 )
8393 go func () {
94+ defer wg .Done ()
8495 NonSlidingUntil (func () {
8596 called <- struct {}{}
8697 }, 0 , ch )
@@ -89,6 +100,7 @@ func TestNonSlidingUntil(t *testing.T) {
89100 <- called
90101 close (ch )
91102 <- called
103+ wg .Wait ()
92104}
93105
94106func TestNonSlidingUntilWithContext (t * testing.T ) {
@@ -100,7 +112,10 @@ func TestNonSlidingUntilWithContext(t *testing.T) {
100112
101113 ctx , cancel = context .WithCancel (context .TODO ())
102114 called := make (chan struct {})
115+ wg := sync.WaitGroup {}
116+ wg .Add (1 )
103117 go func () {
118+ defer wg .Done ()
104119 NonSlidingUntilWithContext (ctx , func (context.Context ) {
105120 called <- struct {}{}
106121 }, 0 )
@@ -109,6 +124,7 @@ func TestNonSlidingUntilWithContext(t *testing.T) {
109124 <- called
110125 cancel ()
111126 <- called
127+ wg .Wait ()
112128}
113129
114130func TestUntilReturnsImmediately (t * testing.T ) {
@@ -138,7 +154,10 @@ func TestJitterUntil(t *testing.T) {
138154
139155 ch = make (chan struct {})
140156 called := make (chan struct {})
157+ wg := sync.WaitGroup {}
158+ wg .Add (1 )
141159 go func () {
160+ defer wg .Done ()
142161 JitterUntil (func () {
143162 called <- struct {}{}
144163 }, 0 , 1.0 , true , ch )
@@ -147,6 +166,7 @@ func TestJitterUntil(t *testing.T) {
147166 <- called
148167 close (ch )
149168 <- called
169+ wg .Wait ()
150170}
151171
152172func TestJitterUntilWithContext (t * testing.T ) {
@@ -158,7 +178,10 @@ func TestJitterUntilWithContext(t *testing.T) {
158178
159179 ctx , cancel = context .WithCancel (context .TODO ())
160180 called := make (chan struct {})
181+ wg := sync.WaitGroup {}
182+ wg .Add (1 )
161183 go func () {
184+ defer wg .Done ()
162185 JitterUntilWithContext (ctx , func (context.Context ) {
163186 called <- struct {}{}
164187 }, 0 , 1.0 , true )
@@ -167,6 +190,7 @@ func TestJitterUntilWithContext(t *testing.T) {
167190 <- called
168191 cancel ()
169192 <- called
193+ wg .Wait ()
170194}
171195
172196func TestJitterUntilReturnsImmediately (t * testing.T ) {
@@ -220,7 +244,10 @@ func TestJitterUntilNegativeFactor(t *testing.T) {
220244 ch := make (chan struct {})
221245 called := make (chan struct {})
222246 received := make (chan struct {})
247+ wg := sync.WaitGroup {}
248+ wg .Add (1 )
223249 go func () {
250+ defer wg .Done ()
224251 JitterUntil (func () {
225252 called <- struct {}{}
226253 <- received
@@ -238,6 +265,7 @@ func TestJitterUntilNegativeFactor(t *testing.T) {
238265 if now .Add (3 * time .Second ).Before (time .Now ()) {
239266 t .Errorf ("JitterUntil did not returned after predefined period with negative jitter factor when the stop chan was closed inside the func" )
240267 }
268+ wg .Wait ()
241269}
242270
243271func TestExponentialBackoff (t * testing.T ) {
@@ -440,7 +468,10 @@ func TestPollForever(t *testing.T) {
440468 errc := make (chan error , 1 )
441469 done := make (chan struct {}, 1 )
442470 complete := make (chan struct {})
471+ wg := sync.WaitGroup {}
472+ wg .Add (1 )
443473 go func () {
474+ defer wg .Done ()
444475 f := ConditionFunc (func () (bool , error ) {
445476 ch <- struct {}{}
446477 select {
@@ -479,7 +510,9 @@ func TestPollForever(t *testing.T) {
479510
480511 // at most one poll notification should be sent once we return from the condition
481512 done <- struct {}{}
513+ wg .Add (1 )
482514 go func () {
515+ defer wg .Done ()
483516 for i := 0 ; i < 2 ; i ++ {
484517 _ , open := <- ch
485518 if ! open {
@@ -493,6 +526,7 @@ func TestPollForever(t *testing.T) {
493526 if len (errc ) != 0 {
494527 t .Fatal (<- errc )
495528 }
529+ wg .Wait ()
496530}
497531
498532func Test_waitFor (t * testing.T ) {
@@ -631,8 +665,10 @@ func TestPollUntil(t *testing.T) {
631665 stopCh := make (chan struct {})
632666 called := make (chan bool )
633667 pollDone := make (chan struct {})
634-
668+ wg := sync.WaitGroup {}
669+ wg .Add (1 )
635670 go func () {
671+ defer wg .Done ()
636672 PollUntil (time .Microsecond , ConditionFunc (func () (bool , error ) {
637673 called <- true
638674 return false , nil
@@ -655,6 +691,7 @@ func TestPollUntil(t *testing.T) {
655691 // make sure we finished the poll
656692 <- pollDone
657693 close (called )
694+ wg .Wait ()
658695}
659696
660697func TestBackoff_Step (t * testing.T ) {
0 commit comments