MCPcopy
hub / github.com/kubernetes/client-go / TestCheckRetryClosesBody

Function TestCheckRetryClosesBody

rest/request_test.go:1322–1359  ·  rest/request_test.go::TestCheckRetryClosesBody
(t *testing.T)

Source from the content-addressed store, hash-verified

1320}
1321
1322func 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
1361func TestConnectionResetByPeerIsRetried(t *testing.T) {
1362 count := 0

Callers

nothing calls this directly

Calls 12

testRESTClientFunction · 0.85
BodyMethod · 0.80
TimeoutMethod · 0.80
SuffixMethod · 0.80
PrefixMethod · 0.80
LogfMethod · 0.65
SetMethod · 0.65
ErrorMethod · 0.65
CloseMethod · 0.65
DoRawMethod · 0.65
VerbMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected