This repository has been archived by the owner on Oct 11, 2024. It is now read-only.
forked from gojek/heimdall
-
Notifications
You must be signed in to change notification settings - Fork 0
/
backoff_test.go
50 lines (34 loc) · 1.64 KB
/
backoff_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
44
45
46
47
48
49
50
package heimdall
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestExponentialBackoffNextTime(t *testing.T) {
exponentialBackoff := NewExponentialBackoff(2*time.Millisecond, 10*time.Millisecond, 2.0, 1*time.Millisecond)
assert.True(t, 4*time.Millisecond <= exponentialBackoff.Next(1))
}
func TestExponentialBackoffMaxTimeoutCrossed(t *testing.T) {
exponentialBackoff := NewExponentialBackoff(2*time.Millisecond, 9*time.Millisecond, 2.0, 1*time.Millisecond)
assert.True(t, 9*time.Millisecond <= exponentialBackoff.Next(3))
}
func TestExponentialBackoffMaxTimeoutReached(t *testing.T) {
exponentialBackoff := NewExponentialBackoff(2*time.Millisecond, 10*time.Millisecond, 2.0, 1*time.Millisecond)
assert.True(t, 10*time.Millisecond <= exponentialBackoff.Next(3))
}
func TestExponentialBackoffWhenRetryIsZero(t *testing.T) {
exponentialBackoff := NewExponentialBackoff(2*time.Millisecond, 10*time.Millisecond, 2.0, 1*time.Millisecond)
assert.True(t, 0*time.Millisecond <= exponentialBackoff.Next(0))
}
func TestExponentialBackoffJitter(t *testing.T) {
exponentialBackoff := NewExponentialBackoff(2*time.Millisecond, 10*time.Millisecond, 2.0, 2*time.Millisecond)
assert.True(t, 4*time.Millisecond <= exponentialBackoff.Next(1))
}
func TestConstantBackoffNextTime(t *testing.T) {
constantBackoff := NewConstantBackoff(100*time.Millisecond, 50*time.Millisecond)
assert.True(t, 100*time.Millisecond <= constantBackoff.Next(1))
}
func TestConstantBackoffWhenRetryIsZero(t *testing.T) {
constantBackoff := NewConstantBackoff(100*time.Millisecond, 50*time.Millisecond)
assert.True(t, 0*time.Millisecond <= constantBackoff.Next(0))
}