...
1
16
17 package ipam
18
19 import (
20 "errors"
21 "testing"
22 "time"
23 )
24
25 func TestTimeout(t *testing.T) {
26 time10s := 10 * time.Second
27 time5s := 5 * time.Second
28 timeout := &Timeout{
29 Resync: time10s,
30 MaxBackoff: time5s,
31 InitialRetry: time.Second,
32 }
33
34 for _, testStep := range []struct {
35 err error
36 want time.Duration
37 }{
38 {nil, time10s},
39 {nil, time10s},
40 {errors.New("x"), time.Second},
41 {errors.New("x"), 2 * time.Second},
42 {errors.New("x"), 4 * time.Second},
43 {errors.New("x"), 5 * time.Second},
44 {errors.New("x"), 5 * time.Second},
45 {nil, time10s},
46 {nil, time10s},
47 {errors.New("x"), time.Second},
48 {errors.New("x"), 2 * time.Second},
49 {nil, time10s},
50 } {
51 timeout.Update(testStep.err == nil)
52 next := timeout.Next()
53 if next != testStep.want {
54 t.Errorf("timeout.next(%v) = %v, want %v", testStep.err, next, testStep.want)
55 }
56 }
57 }
58
View as plain text