Skip to content

Commit

Permalink
Make the backoff test better and fix a typo (#251)
Browse files Browse the repository at this point in the history
Signed-off-by: sword-jin <rrylee1994@gmail.com>
  • Loading branch information
sword-jin authored Jan 17, 2024
1 parent 425c1e0 commit d5efaaa
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
31 changes: 21 additions & 10 deletions v2/workloadapi/backoff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,37 @@ import (
)

func TestBackoff(t *testing.T) {
b := newBackoff()
b.InitialDelay = time.Second
b.MaxDelay = 30 * time.Second
new := func() *backoff { //nolint:all
b := newBackoff()
b.InitialDelay = time.Second
b.MaxDelay = 30 * time.Second
return b
}

t.Run("test max", func(t *testing.T) {
testUntilMax := func(t *testing.T, b *backoff) {
for i := 1; i < 30; i++ {
require.Equal(t, time.Duration(i)*time.Second, b.Duration())
}
require.Equal(t, 30*time.Second, b.Duration())
require.Equal(t, 30*time.Second, b.Duration())
require.Equal(t, 30*time.Second, b.Duration())
}

t.Run("test max", func(t *testing.T) {
t.Parallel()

b := new()
testUntilMax(t, b)
})

t.Run("test reset", func(t *testing.T) {
t.Parallel()

b := new()
testUntilMax(t, b)

b.Reset()
for i := 1; i < 30; i++ {
require.Equal(t, time.Duration(i)*time.Second, b.Duration())
}
require.Equal(t, 30*time.Second, b.Duration())
require.Equal(t, 30*time.Second, b.Duration())
require.Equal(t, 30*time.Second, b.Duration())

testUntilMax(t, b)
})
}
2 changes: 1 addition & 1 deletion v2/workloadapi/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (w *watcher) Close() error {
w.cancel()
w.wg.Wait()

// Close() can be called by New() to close a partially intialized source.
// Close() can be called by New() to close a partially initialized source.
// Only close the client if it has been set and the source owns it.
if w.client != nil && w.ownsClient {
w.closeErr = w.client.Close()
Expand Down

0 comments on commit d5efaaa

Please sign in to comment.