(t *testing.T)
| 82 | } |
| 83 | |
| 84 | func TestRetryWithBackoff(t *testing.T) { |
| 85 | tests := []struct { |
| 86 | deltaTime time.Duration |
| 87 | returnError bool |
| 88 | functionCalled bool |
| 89 | }{ |
| 90 | {0 * time.Second, true, true}, |
| 91 | {4 * time.Second, true, false}, |
| 92 | {6 * time.Second, true, true}, |
| 93 | {9 * time.Second, true, false}, |
| 94 | {11 * time.Second, true, true}, |
| 95 | {14 * time.Second, true, false}, |
| 96 | {16 * time.Second, false, true}, |
| 97 | {16 * time.Minute, true, true}, |
| 98 | {4 * time.Second, true, false}, |
| 99 | {6 * time.Second, true, true}, |
| 100 | } |
| 101 | |
| 102 | var returnError, functionCalled bool |
| 103 | |
| 104 | g := func() (int64, error) { |
| 105 | functionCalled = true |
| 106 | if returnError { |
| 107 | return 1, api.ErrTimeout |
| 108 | } |
| 109 | return 1, nil |
| 110 | } |
| 111 | |
| 112 | c := ResettableCached(g, 15*time.Minute) |
| 113 | clock := clock.NewMock() |
| 114 | c.clock = clock |
| 115 | |
| 116 | for _, tt := range tests { |
| 117 | functionCalled = false |
| 118 | returnError = tt.returnError |
| 119 | |
| 120 | clock.Add(tt.deltaTime) |
| 121 | |
| 122 | _, err := c.Get() |
| 123 | |
| 124 | if returnError { |
| 125 | assert.Error(t, err) |
| 126 | } |
| 127 | |
| 128 | assert.Equal(t, tt.functionCalled, functionCalled) |
| 129 | } |
| 130 | } |
nothing calls this directly
no test coverage detected