make sure the test is good
@@ -4,6 +4,7 @@ import (
"context"
"github.com/alaingilbert/clockwork"
"github.com/magiconair/properties/assert"
+ "sync"
"sync/atomic"
"testing"
"time"
@@ -12,6 +13,8 @@ import (
func TestExponentialBackoff_Wait(t *testing.T) {
var counter uint32
clock := clockwork.NewFakeClock()
+ wg := &sync.WaitGroup{}
+ wg.Add(1)
go func() {
clock.BlockUntil(1)
clock.Advance(1000 * time.Millisecond)
@@ -23,6 +26,7 @@ func TestExponentialBackoff_Wait(t *testing.T) {
clock.Advance(4000 * time.Millisecond)
clock.BlockUntil(0)
atomic.AddUint32(&counter, 1)
+ wg.Done()
}()
e := NewExponentialBackoff(context.Background(), 60)
e.SetClock(clock)
@@ -30,5 +34,6 @@ func TestExponentialBackoff_Wait(t *testing.T) {
e.Wait() // Wait 1s
e.Wait() // Wait 2s
e.Wait() // Wait 4s
+ wg.Wait()
assert.Equal(t, uint32(1), atomic.LoadUint32(&counter))
}
