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

Function TestConnectionResetByPeerIsRetried

rest/request_test.go:1361–1388  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1359}
1360
1361func 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
1390func TestCheckRetryHandles429And5xx(t *testing.T) {
1391 count := 0

Callers

nothing calls this directly

Calls 4

DoMethod · 0.95
clientFuncFuncType · 0.85
RawMethod · 0.80
ErrorfMethod · 0.65

Tested by

no test coverage detected