Using withExponentialBackoff as the backoff function sends retries initially with a 1-second delay, but doubling after each attempt to a maximum delay of 1-minute. Each backoff time gets an additional
()
| 134 | // initially with a 1-second delay, but doubling after each attempt to |
| 135 | // a maximum delay of 1-minute. Each backoff time gets an additional |
| 136 | func withExponentialBackoffAndJitter() string { |
| 137 | res, err := sendRequest() |
| 138 | base, cap := time.Second, time.Minute |
| 139 | |
| 140 | for backoff := base; err != nil; backoff <<= 1 { |
| 141 | if backoff > cap { |
| 142 | backoff = cap |
| 143 | } |
| 144 | |
| 145 | jitter := rand.Int63n(int64(backoff * 3)) |
| 146 | sleep := base + time.Duration(jitter) |
| 147 | time.Sleep(sleep) |
| 148 | res, err = sendRequest() |
| 149 | } |
| 150 | |
| 151 | return res |
| 152 | } |
| 153 | |
| 154 | // sendRequest simulates sending a request. It always returns an |
| 155 | // error after a short delay. |
nothing calls this directly
no test coverage detected