(t *testing.T)
| 1359 | } |
| 1360 | |
| 1361 | func TestConnectionResetByPeerIsRetried(t *testing.T) { |
| 1362 | count := 0 |
| 1363 | backoff := &testBackoffManager{} |
| 1364 | req := &Request{ |
| 1365 | verb: "GET", |
| 1366 | client: clientFunc(func(req *http.Request) (*http.Response, error) { |
| 1367 | count++ |
| 1368 | if count >= 3 { |
| 1369 | return &http.Response{ |
| 1370 | StatusCode: 200, |
| 1371 | Body: ioutil.NopCloser(bytes.NewReader([]byte{})), |
| 1372 | }, nil |
| 1373 | } |
| 1374 | return nil, &net.OpError{Err: syscall.ECONNRESET} |
| 1375 | }), |
| 1376 | backoffMgr: backoff, |
| 1377 | } |
| 1378 | // We expect two retries of "connection reset by peer" and the success. |
| 1379 | _, err := req.Do().Raw() |
| 1380 | if err != nil { |
| 1381 | t.Errorf("Unexpected error: %v", err) |
| 1382 | } |
| 1383 | // We have a sleep before each retry (including the initial one) and for |
| 1384 | // every "retry-after" call - thus 5 together. |
| 1385 | if len(backoff.sleeps) != 5 { |
| 1386 | t.Errorf("Expected 5 retries, got: %d", len(backoff.sleeps)) |
| 1387 | } |
| 1388 | } |
| 1389 | |
| 1390 | func TestCheckRetryHandles429And5xx(t *testing.T) { |
| 1391 | count := 0 |
nothing calls this directly
no test coverage detected