forked from edgelaboratories/heimdall
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathretry_test.go
37 lines (27 loc) · 1010 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
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))
}