forked from go-resty/resty
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathretry_test.go
40 lines (34 loc) · 947 Bytes
/
retry_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright (c) 2015-2016 Jeevanandam M ([email protected]), All rights reserved.
// resty source code and usage is governed by a MIT style
// license that can be found in the LICENSE file.
package resty
import (
"errors"
"testing"
)
func TestBackoffSuccess(t *testing.T) {
attempts := 3
externalCounter := 0
retryErr := Backoff(func() error {
externalCounter++
if externalCounter < attempts {
return errors.New("Not yet got the number we're after...")
}
return nil
})
assertError(t, retryErr)
assertEqual(t, externalCounter, attempts)
}
func TestBackoffTenAttemptsSuccess(t *testing.T) {
attempts := 10
externalCounter := 0
retryErr := Backoff(func() error {
externalCounter++
if externalCounter < attempts {
return errors.New("Not yet got the number we're after...")
}
return nil
}, Retries(attempts), WaitTime(5), MaxWaitTime(500))
assertError(t, retryErr)
assertEqual(t, externalCounter, attempts)
}