-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathretry_internal_test.go
74 lines (63 loc) · 1.6 KB
/
retry_internal_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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package retry
import (
"context"
"testing"
"time"
)
func TestFreezeBackoffAfterFirstUse(t *testing.T) {
attempts := 1
initialDelay := 1 * time.Millisecond
maxDelay := 1 * time.Millisecond
factor := 1.0
jitter := 1.0
b := &Backoff{
Attempts: attempts,
InitialDelay: initialDelay,
MaxDelay: maxDelay,
Factor: factor,
Jitter: jitter,
}
It(context.Background(), b, func(ctx context.Context) error {
return nil
})
b.Attempts = 7
b.InitialDelay = 7 * time.Millisecond
b.MaxDelay = 7 * time.Millisecond
b.Factor = 7.0
b.Jitter = 7.0
It(context.Background(), b, func(ctx context.Context) error {
return nil
})
if b.Attempts != 7 || b.attempts != attempts ||
b.InitialDelay != 7*time.Millisecond || b.initialDelay != initialDelay ||
b.MaxDelay != 7*time.Millisecond || b.maxDelay != maxDelay ||
b.Factor != 7.0 || b.factor != factor ||
b.Jitter != 7.0 || b.jitter != jitter {
t.Error("public fields should change, private should have been frozen")
}
}
func TestFreezeBackoffWithBadInputs(t *testing.T) {
attempts := -1
initialDelay := -1 * time.Millisecond
maxDelay := 0 * time.Millisecond
factor := 0.0
jitter := -1.0
b := &Backoff{
Attempts: attempts,
InitialDelay: initialDelay,
MaxDelay: maxDelay,
Factor: factor,
Jitter: jitter,
}
It(context.Background(), b, func(ctx context.Context) error {
return nil
})
if b.attempts != 1 ||
b.initialDelay != 0 ||
b.maxDelay != Forever ||
b.factor != 1 ||
b.jitter != 0 ||
b.skipJitter != true {
t.Error("public fields should change, private should have been frozen")
}
}