File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change
1
+ package errors
2
+
3
+ import (
4
+ "errors"
5
+ "testing"
6
+
7
+ "github.com/stretchr/testify/assert"
8
+ )
9
+
10
+ func TestRetryAfter (t * testing.T ) {
11
+ calls := 0
12
+ ret := RetryAfter (10 , func () error {
13
+ calls ++
14
+ return nil
15
+ }, 0 )
16
+ assert .NoError (t , ret )
17
+ assert .Equal (t , 1 , calls )
18
+ }
19
+
20
+ func TestRetryAfterFailure (t * testing.T ) {
21
+ calls := 0
22
+ ret := RetryAfter (10 , func () error {
23
+ calls ++
24
+ return errors .New ("failed" )
25
+ }, 0 )
26
+ assert .EqualError (t , ret , "failed" )
27
+ assert .Equal (t , 1 , calls )
28
+ }
29
+
30
+ func TestRetryAfterMaxAttempts (t * testing.T ) {
31
+ calls := 0
32
+ ret := RetryAfter (3 , func () error {
33
+ calls ++
34
+ return & RetriableError {Err : errors .New ("failed" )}
35
+ }, 0 )
36
+ assert .EqualError (t , ret , "Temporary Error: failed\n Temporary Error: failed\n Temporary Error: failed" )
37
+ assert .Equal (t , 3 , calls )
38
+ }
39
+
40
+ func TestRetryAfterSuccessAfterFailures (t * testing.T ) {
41
+ calls := 0
42
+ ret := RetryAfter (5 , func () error {
43
+ calls ++
44
+ if calls < 3 {
45
+ return & RetriableError {Err : errors .New ("failed" )}
46
+ }
47
+ return nil
48
+ }, 0 )
49
+ assert .NoError (t , ret )
50
+ assert .Equal (t , 3 , calls )
51
+ }
You can’t perform that action at this time.
0 commit comments