@@ -17,13 +17,14 @@ func TestAttempts(t *testing.T) {
17
17
count := 0
18
18
start := time .Now ()
19
19
20
- Attempts (5 , time .Millisecond , func () error {
20
+ const sleep = time .Millisecond * 10
21
+ Attempts (5 , sleep , func () error {
21
22
count ++
22
23
return errors .Errorf ("asdfasdf" )
23
24
})
24
25
25
26
assert .Equal (t , 5 , count )
26
- assert .WithinDuration (t , start .Add (time . Millisecond * 5 ), time .Now (), time . Millisecond * 1 )
27
+ assert .WithinDuration (t , start .Add (sleep * 5 ), time .Now (), sleep )
27
28
})
28
29
29
30
t .Run ("returns as soon as error is nil" , func (t * testing.T ) {
@@ -40,22 +41,24 @@ func TestTimeout(t *testing.T) {
40
41
count := 0
41
42
start := time .Now ()
42
43
44
+ const sleep = time .Millisecond * 10
45
+
43
46
// The timing here is a little sketchy.
44
- Timeout ((time . Millisecond * 5 ), time . Millisecond , func () error {
47
+ Timeout ((sleep * 5 ), sleep , func () error {
45
48
count ++
46
49
return errors .Errorf ("asdfasdf" )
47
50
})
48
51
49
52
assert .Equal (t , 5 , count )
50
- assert .WithinDuration (t , start .Add (time . Millisecond * 5 ), time .Now (), time . Millisecond * 1 )
53
+ assert .WithinDuration (t , start .Add (sleep * 5 ), time .Now (), sleep )
51
54
})
52
55
53
56
t .Run ("returns as soon as error is nil" , func (t * testing.T ) {
54
57
start := time .Now ()
55
58
Timeout ((time .Hour ), time .Minute , func () error {
56
59
return nil
57
60
})
58
- assert .WithinDuration (t , time .Now (), start , time .Millisecond )
61
+ assert .WithinDuration (t , time .Now (), start , time .Millisecond * 10 )
59
62
})
60
63
}
61
64
0 commit comments