(t *testing.T)
| 1320 | } |
| 1321 | |
| 1322 | func TestCheckRetryClosesBody(t *testing.T) { |
| 1323 | count := 0 |
| 1324 | ch := make(chan struct{}) |
| 1325 | testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { |
| 1326 | count++ |
| 1327 | t.Logf("attempt %d", count) |
| 1328 | if count >= 5 { |
| 1329 | w.WriteHeader(http.StatusOK) |
| 1330 | close(ch) |
| 1331 | return |
| 1332 | } |
| 1333 | w.Header().Set("Retry-After", "1") |
| 1334 | http.Error(w, "Too many requests, please try again later.", http.StatusTooManyRequests) |
| 1335 | })) |
| 1336 | defer testServer.Close() |
| 1337 | |
| 1338 | backoffMgr := &testBackoffManager{} |
| 1339 | expectedSleeps := []time.Duration{0, time.Second, 0, time.Second, 0, time.Second, 0, time.Second, 0} |
| 1340 | |
| 1341 | c := testRESTClient(t, testServer) |
| 1342 | c.createBackoffMgr = func() BackoffManager { return backoffMgr } |
| 1343 | _, err := c.Verb("POST"). |
| 1344 | Prefix("foo", "bar"). |
| 1345 | Suffix("baz"). |
| 1346 | Timeout(time.Second). |
| 1347 | Body([]byte(strings.Repeat("abcd", 1000))). |
| 1348 | DoRaw() |
| 1349 | if err != nil { |
| 1350 | t.Fatalf("Unexpected error: %v %#v", err, err) |
| 1351 | } |
| 1352 | <-ch |
| 1353 | if count != 5 { |
| 1354 | t.Errorf("unexpected retries: %d", count) |
| 1355 | } |
| 1356 | if !reflect.DeepEqual(backoffMgr.sleeps, expectedSleeps) { |
| 1357 | t.Errorf("unexpected sleeps, expected: %v, got: %v", expectedSleeps, backoffMgr.sleeps) |
| 1358 | } |
| 1359 | } |
| 1360 | |
| 1361 | func TestConnectionResetByPeerIsRetried(t *testing.T) { |
| 1362 | count := 0 |
nothing calls this directly
no test coverage detected