MCPcopy
hub / github.com/urllib3/urllib3 / test_respect_retry_after_header_sleep

Method test_respect_retry_after_header_sleep

test/test_retry.py:411–440  ·  view source on GitHub ↗
(
        self,
        retry_after_header: str,
        respect_retry_after_header: bool,
        sleep_duration: int | None,
    )

Source from the content-addressed store, hash-verified

409 )
410 @pytest.mark.usefixtures("stub_timezone")
411 def test_respect_retry_after_header_sleep(
412 self,
413 retry_after_header: str,
414 respect_retry_after_header: bool,
415 sleep_duration: int | None,
416 ) -> None:
417 retry = Retry(respect_retry_after_header=respect_retry_after_header)
418
419 with (
420 mock.patch(
421 "time.time",
422 return_value=datetime.datetime(
423 2019, 6, 3, 11, tzinfo=datetime.timezone.utc
424 ).timestamp(),
425 ),
426 mock.patch("time.sleep") as sleep_mock,
427 ):
428 # for the default behavior, it must be in RETRY_AFTER_STATUS_CODES
429 response = HTTPResponse(
430 status=503, headers={"Retry-After": retry_after_header}
431 )
432
433 retry.sleep(response)
434
435 # The expected behavior is that we'll only sleep if respecting
436 # this header (since we won't have any backoff sleep attempts)
437 if respect_retry_after_header and sleep_duration is not None:
438 sleep_mock.assert_called_with(sleep_duration)
439 else:
440 sleep_mock.assert_not_called()

Callers

nothing calls this directly

Calls 3

sleepMethod · 0.95
RetryClass · 0.90
HTTPResponseClass · 0.90

Tested by

no test coverage detected