Skip to content

Commit

Permalink
make sure the test is good
Browse files Browse the repository at this point in the history
  • Loading branch information
alaingilbert committed Aug 21, 2022
1 parent 12d87a6 commit 10d77a2
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/wrapper/exponentialBackoff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"github.com/alaingilbert/clockwork"
"github.com/magiconair/properties/assert"
"sync"
"sync/atomic"
"testing"
"time"
Expand All @@ -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)
Expand All @@ -23,12 +26,14 @@ 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)
e.Wait() // First time has no wait
e.Wait() // Wait 1s
e.Wait() // Wait 2s
e.Wait() // Wait 4s
wg.Wait()
assert.Equal(t, uint32(1), atomic.LoadUint32(&counter))
}

0 comments on commit 10d77a2

Please sign in to comment.