コード例 #1
0
    def test_respect_retry_after_header_sleep(
        self, retry_after_header, respect_retry_after_header, sleep_duration
    ):
        retry = Retry(respect_retry_after_header=respect_retry_after_header)

        # Date header syntax can specify an absolute date; compare this to the
        # time in the parametrized inputs above.
        current_time = mock.MagicMock(
            return_value=time.mktime(
                datetime.datetime(year=2019, month=6, day=3, hour=11).timetuple()
            )
        )

        with mock.patch("time.sleep") as sleep_mock, mock.patch(
            "time.time", current_time
        ):
            # for the default behavior, it must be in RETRY_AFTER_STATUS_CODES
            response = HTTPResponse(
                status=503, headers={"Retry-After": retry_after_header}
            )

            retry.sleep(response)

            # The expected behavior is that we'll only sleep if respecting
            # this header (since we won't have any backoff sleep attempts)
            if respect_retry_after_header and sleep_duration is not None:
                sleep_mock.assert_called_with(sleep_duration)
            else:
                sleep_mock.assert_not_called()
コード例 #2
0
    def test_respect_retry_after_header_sleep(self, retry_after_header,
                                              respect_retry_after_header,
                                              sleep_duration):
        retry = Retry(respect_retry_after_header=respect_retry_after_header)

        with mock.patch("time.sleep") as sleep_mock:
            # for the default behavior, it must be in RETRY_AFTER_STATUS_CODES
            response = HTTPResponse(
                status=503, headers={"Retry-After": retry_after_header})

            retry.sleep(response)

            # The expected behavior is that we'll only sleep if respecting
            # this header (since we won't have any backoff sleep attempts)
            if respect_retry_after_header and sleep_duration is not None:
                sleep_mock.assert_called_with(sleep_duration)
            else:
                sleep_mock.assert_not_called()
コード例 #3
0
 def test_sleep(self) -> None:
     # sleep a very small amount of time so our code coverage is happy
     retry = Retry(backoff_factor=0.0001)
     retry = retry.increment(method="GET")
     retry = retry.increment(method="GET")
     retry.sleep()
コード例 #4
0
ファイル: test_retry.py プロジェクト: birm/urllib3
 def test_sleep(self):
     # sleep a very small amount of time so our code coverage is happy
     retry = Retry(backoff_factor=0.0001)
     retry = retry.increment()
     retry = retry.increment()
     retry.sleep()