def testDefaultExceptionHandler(self): """Ensures exception handles swallows (retries)""" mock_http_content = 'content'.encode('utf8') for exception_arg in (http_client.BadStatusLine('line'), http_client.IncompleteRead('partial'), http_client.ResponseNotReady(), socket.error(), socket.gaierror(), httplib2.ServerNotFoundError(), ValueError(), oauth2client.client.HttpAccessTokenRefreshError( status=503), exceptions.RequestError(), exceptions.BadStatusCodeError({'status': 503}, mock_http_content, 'url'), exceptions.RetryAfterError({'status': 429}, mock_http_content, 'url', 0)): retry_args = http_wrapper.ExceptionRetryArgs( http={'connections': {}}, http_request=_MockHttpRequest(), exc=exception_arg, num_retries=0, max_retry_wait=0, total_wait_sec=0) # Disable time.sleep for this handler as it is called with # a minimum value of 1 second. with patch('time.sleep', return_value=None): http_wrapper.HandleExceptionsAndRebuildHttpConnections( retry_args)
def CheckFailResult(urls, first_run=True, exception=http_client.ResponseNotReady()): message = 'Reachability Check {0}.\n'.format('failed' if first_run else 'still does not pass') def CreateFailure(url, err): msg = 'Cannot reach {0} ({1})'.format(url, type(err).__name__) return check_base.Failure(message=msg, exception=err) failures = [CreateFailure(url, exception) for url in urls] for failure in failures: message += ' {0}\n'.format(failure.message) if first_run: message += ('Network connection problems may be due to proxy or firewall ' 'settings.\n') return check_base.Result(passed=False, message=message, failures=failures)
def side_effect(mo, **kwargs): self.assertEqual(managed_object, mo._type) self.assertEqual(managed_object, mo.value) raise httplib.ResponseNotReady()