def test_w_RetryAfterError(self):
        from gcloud.streaming.exceptions import RetryAfterError
        from gcloud.streaming.http_wrapper import TOO_MANY_REQUESTS
        RETRY_AFTER = 25
        response = _Response(TOO_MANY_REQUESTS, RETRY_AFTER)
        exc = RetryAfterError.from_response(response)
        retry_args = self._build_retry_args(exc)
        monkey, logged, slept = self._monkeyMUT()

        with monkey:
            self._callFUT(retry_args)

        self._verify_logged_slept(
            logged, slept,
            'Response returned a retry-after header, retrying', (),
            RETRY_AFTER)
示例#2
0
def _check_response(response):
    """Validate a response

    :type response: :class:`Response`
    :param response: the response to validate

    :raises: :exc:`gcloud.streaming.exceptions.RequestError` if response is
             None, :exc:`gcloud.streaming.exceptions.BadStatusCodeError` if
             response status code indicates an error, or
             :exc:`gcloud.streaming.exceptions.RetryAfterError` if response
             indicates a retry interval.
    """
    if response is None:
        # Caller shouldn't call us if the response is None, but handle anyway.
        raise RequestError('Request did not return a response.')
    elif (response.status_code >= 500
          or response.status_code == TOO_MANY_REQUESTS):
        raise BadStatusCodeError.from_response(response)
    elif response.retry_after:
        raise RetryAfterError.from_response(response)
示例#3
0
def _check_response(response):
    """Validate a response

    :type response: :class:`Response`
    :param response: the response to validate

    :raises: :exc:`gcloud.streaming.exceptions.RequestError` if response is
             None, :exc:`gcloud.streaming.exceptions.BadStatusCodeError` if
             response status code indicates an error, or
             :exc:`gcloud.streaming.exceptions.RetryAfterError` if response
             indicates a retry interval.
    """
    if response is None:
        # Caller shouldn't call us if the response is None, but handle anyway.
        raise RequestError(
            'Request did not return a response.')
    elif (response.status_code >= 500 or
          response.status_code == TOO_MANY_REQUESTS):
        raise BadStatusCodeError.from_response(response)
    elif response.retry_after:
        raise RetryAfterError.from_response(response)
示例#4
0
 def _wo_exception(*args, **kw):
     _created.append((args, kw))
     if _counter:
         _counter.pop()
         raise RetryAfterError(RESPONSE, '', REQUEST.url, 0.1)
     return RESPONSE