# Path: google/resumable_media/common.py
# _SLEEP_RETRY_ERROR_MSG = (
#     "At most one of `max_cumulative_retry` and `max_retries` " "can be specified."
# )
# UPLOAD_CHUNK_SIZE = 262144  # 256 * 1024
# PERMANENT_REDIRECT = http.client.PERMANENT_REDIRECT  # type: ignore
# TOO_MANY_REQUESTS = http.client.TOO_MANY_REQUESTS
# MAX_SLEEP = 64.0
# MAX_CUMULATIVE_RETRY = 600.0
# RETRYABLE = (
#     http.client.TOO_MANY_REQUESTS,  # 429
#     http.client.REQUEST_TIMEOUT,  # 408
#     http.client.INTERNAL_SERVER_ERROR,  # 500
#     http.client.BAD_GATEWAY,  # 502
#     http.client.SERVICE_UNAVAILABLE,  # 503
#     http.client.GATEWAY_TIMEOUT,  # 504
# )
# class InvalidResponse(Exception):
# class DataCorruption(Exception):
# class RetryStrategy(object):
#     def __init__(self, response, *args):
#     def __init__(self, response, *args):
#     def __init__(
#         self,
#         max_sleep=MAX_SLEEP,
#         max_cumulative_retry=None,
#         max_retries=None,
#         initial_delay=1.0,
#         multiplier=2.0,
#     ):
#     def retry_allowed(self, total_sleep, num_retries):
# 
# Path: google/resumable_media/requests/_request_helpers.py
# _DEFAULT_RETRY_STRATEGY = common.RetryStrategy()
# _SINGLE_GET_CHUNK_SIZE = 8192
# _DEFAULT_CONNECT_TIMEOUT = 61
# _DEFAULT_READ_TIMEOUT = 60
# _CONNECTION_ERROR_CLASSES = (
#     requests.exceptions.ConnectionError,
#     requests.exceptions.ChunkedEncodingError,
#     urllib3.exceptions.ProtocolError,
#     ConnectionError,  # Python 3.x only, superclass of ConnectionResetError.
# )
# class RequestsMixin(object):
# class RawRequestsMixin(RequestsMixin):
#     def _get_status_code(response):
#     def _get_headers(response):
#     def _get_body(response):
#     def _get_body(response):
# def wait_and_retry(func, get_status_code, retry_strategy):


import http.client
import mock
import pytest  # type: ignore
import requests.exceptions
import urllib3.exceptions  # type: ignore
from google.resumable_media import common
from google.resumable_media.requests import _request_helpers

        assert func.call_count == 4
        assert func.mock_calls == [mock.call()] * 4

        assert randint_mock.call_count == 3
        assert randint_mock.mock_calls == [mock.call(0, 1000)] * 3

        assert sleep_mock.call_count == 3
        sleep_mock.assert_any_call(3.125)  # initial delay 3 + jitter 0.125
        sleep_mock.assert_any_call(
            12.625
        )  # previous delay 3 * multiplier 4 + jitter 0.625
        sleep_mock.assert_any_call(
            48.375
        )  # previous delay 12 * multiplier 4 + jitter 0.375

    @mock.patch("time.sleep")
    @mock.patch("random.randint")
    def test_success_with_retry_connection_error(self, randint_mock, sleep_mock):
        randint_mock.side_effect = [125, 625, 375]

        response = _make_response(http.client.NOT_FOUND)
        responses = [
            ConnectionResetError,  # Subclass of ConnectionError
            urllib3.exceptions.ConnectionError,
            requests.exceptions.ConnectionError,
            response,
        ]
        func = mock.Mock(side_effect=responses, spec=[])


# Path: google/resumable_media/common.py
# _SLEEP_RETRY_ERROR_MSG = (
#     "At most one of `max_cumulative_retry` and `max_retries` " "can be specified."
# )
# UPLOAD_CHUNK_SIZE = 262144  # 256 * 1024
# PERMANENT_REDIRECT = http.client.PERMANENT_REDIRECT  # type: ignore
# TOO_MANY_REQUESTS = http.client.TOO_MANY_REQUESTS
# MAX_SLEEP = 64.0
# MAX_CUMULATIVE_RETRY = 600.0
# RETRYABLE = (
#     http.client.TOO_MANY_REQUESTS,  # 429
#     http.client.REQUEST_TIMEOUT,  # 408
#     http.client.INTERNAL_SERVER_ERROR,  # 500
#     http.client.BAD_GATEWAY,  # 502
#     http.client.SERVICE_UNAVAILABLE,  # 503
#     http.client.GATEWAY_TIMEOUT,  # 504
# )
# class InvalidResponse(Exception):
# class DataCorruption(Exception):
# class RetryStrategy(object):
#     def __init__(self, response, *args):
#     def __init__(self, response, *args):
#     def __init__(
#         self,
#         max_sleep=MAX_SLEEP,
#         max_cumulative_retry=None,
#         max_retries=None,
#         initial_delay=1.0,
#         multiplier=2.0,
#     ):
#     def retry_allowed(self, total_sleep, num_retries):
# 
# Path: google/resumable_media/requests/_request_helpers.py
# _DEFAULT_RETRY_STRATEGY = common.RetryStrategy()
# _SINGLE_GET_CHUNK_SIZE = 8192
# _DEFAULT_CONNECT_TIMEOUT = 61
# _DEFAULT_READ_TIMEOUT = 60
# _CONNECTION_ERROR_CLASSES = (
#     requests.exceptions.ConnectionError,
#     requests.exceptions.ChunkedEncodingError,
#     urllib3.exceptions.ProtocolError,
#     ConnectionError,  # Python 3.x only, superclass of ConnectionResetError.
# )
# class RequestsMixin(object):
# class RawRequestsMixin(RequestsMixin):
#     def _get_status_code(response):
#     def _get_headers(response):
#     def _get_body(response):
#     def _get_body(response):
# def wait_and_retry(func, get_status_code, retry_strategy):


# Path: tests/unit/requests/test__helpers.py
import http.client
import mock
import pytest  # type: ignore
import requests.exceptions
import urllib3.exceptions  # type: ignore
from google.resumable_media import common
from google.resumable_media.requests import _request_helpers


        assert func.call_count == 4
        assert func.mock_calls == [mock.call()] * 4

        assert randint_mock.call_count == 3
        assert randint_mock.mock_calls == [mock.call(0, 1000)] * 3

        assert sleep_mock.call_count == 3
        sleep_mock.assert_any_call(3.125)  # initial delay 3 + jitter 0.125
        sleep_mock.assert_any_call(
            12.625
        )  # previous delay 3 * multiplier 4 + jitter 0.625
        sleep_mock.assert_any_call(
            48.375
        )  # previous delay 12 * multiplier 4 + jitter 0.375

    @mock.patch("time.sleep")
    @mock.patch("random.randint")
    def test_success_with_retry_connection_error(self, randint_mock, sleep_mock):
        randint_mock.side_effect = [125, 625, 375]

        response = _make_response(http.client.NOT_FOUND)
        responses = [
            ConnectionResetError,  # Subclass of ConnectionError
            urllib3.exceptions.ConnectionError,
            requests.exceptions.ConnectionError,
            response,
        ]
        func = mock.Mock(side_effect=responses, spec=[])


        retry_strategy = common.RetryStrategy()