-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathretry_test.go
56 lines (49 loc) · 880 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import "testing"
// Test when no retry should be necessary
func TestNoRetryNecessary(t *testing.T) {
count := 0
RunRetry(
func() *string {
count++
return nil
},
5,
1)
if count != 1 {
t.Error("Expected count == 1, got", count)
}
}
// Test when retry is necessary, but eventually succeeds
func TestLessThanMaxRetryNecessary(t *testing.T) {
count := 0
RunRetry(
func() *string {
count++
if count < 3 {
ret := "value"
return &ret
}
return nil
},
5,
1)
if count != 3 {
t.Error("Expected count == 3, got", count)
}
}
// Test that it will only retry max times and then stop if the function is never successful
func TestStopAtMax(t *testing.T) {
count := 0
RunRetry(
func() *string {
count++
ret := "value"
return &ret
},
4,
1)
if count != 4 {
t.Error("Expected count == 4, got", count)
}
}