Skip to content

Commit de3f112

Browse files
committed
add TestDoCalls for asserting counts
Signed-off-by: t-kikuc <[email protected]>
1 parent b397ab3 commit de3f112

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

pkg/backoff/backoff_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,15 @@ func TestDo(t *testing.T) {
147147
})
148148
}
149149
}
150+
151+
func TestDoCalls(t *testing.T) {
152+
r := NewRetry(3, NewConstant(time.Millisecond))
153+
assert.Equal(t, 0, r.Calls())
154+
cnt := 0
155+
r.Do(context.TODO(), func() (interface{}, error) {
156+
cnt++
157+
assert.Equal(t, cnt, r.Calls()) // Calls should be 1,2,3
158+
return nil, errors.New("error-to-retry")
159+
})
160+
assert.Equal(t, 4, r.Calls())
161+
}

0 commit comments

Comments
 (0)