-
Notifications
You must be signed in to change notification settings - Fork 214
/
retry_test.go
43 lines (32 loc) · 1.14 KB
/
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
41
42
43
package heimdall
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestRetrierWithExponentialBackoff(t *testing.T) {
exponentialBackoff := NewExponentialBackoff(2*time.Millisecond, 10*time.Millisecond, 2.0, 1*time.Millisecond)
exponentialRetrier := NewRetrier(exponentialBackoff)
assert.True(t, 4*time.Millisecond <= exponentialRetrier.NextInterval(1))
}
func TestRetrierWithConstantBackoff(t *testing.T) {
backoffInterval := 2 * time.Millisecond
maximumJitterInterval := 1 * time.Millisecond
constantBackoff := NewConstantBackoff(backoffInterval, maximumJitterInterval)
constantRetrier := NewRetrier(constantBackoff)
assert.True(t, 2*time.Millisecond <= constantRetrier.NextInterval(1))
}
func TestRetrierFunc(t *testing.T) {
linearRetrier := NewRetrierFunc(func(retry int) time.Duration {
if retry <= 0 {
return 0 * time.Millisecond
}
return time.Duration(retry) * time.Millisecond
})
assert.True(t, 3*time.Millisecond <= linearRetrier.NextInterval(4))
}
func TestNoRetrier(t *testing.T) {
noRetrier := NewNoRetrier()
nextInterval := noRetrier.NextInterval(1)
assert.Equal(t, time.Duration(0), nextInterval)
}