-
Notifications
You must be signed in to change notification settings - Fork 6
/
composite_strategy_test.go
61 lines (56 loc) · 1.32 KB
/
composite_strategy_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
package retry
import (
"testing"
"time"
)
func TestIterationsAndTime(t *testing.T) {
for _, test := range []struct {
attempts int
iterations int
duration time.Duration
}{
{15, 1, time.Millisecond},
{10, 30, time.Millisecond},
} {
tryCase(t, &All{
&CountStrategy{Tries: test.iterations},
&MaximumTimeStrategy{Duration: test.duration},
}, testCase{
name: test,
attempts: test.attempts,
maximum: test.iterations,
maxDuration: test.duration,
step: time.Millisecond / 10,
})
}
}
func TestMinIterationsAndMaxTime(t *testing.T) {
for _, test := range []struct {
attempts int
minIterations int
maxIterations int
duration time.Duration
step time.Duration
}{
{1000, 2, 4, time.Millisecond, time.Millisecond / 3},
{1000, 10, 30, time.Millisecond, time.Millisecond / 9},
} {
// At least minIterations
// At most duration
// At least step between iterations
tryCase(t, &Any{
&CountStrategy{Tries: test.minIterations},
&All{
&MaximumTimeStrategy{Duration: test.duration},
&DelayStrategy{Wait: test.step},
},
}, testCase{
name: test,
attempts: test.attempts,
minimum: test.minIterations,
maximum: test.maxIterations,
maxDuration: test.duration,
step: time.Millisecond / 100,
})
}
}