def testRetryFailWithUrlfetchTimeOut(self): with mock.patch.object(api_utils.urlfetch, 'fetch') as f: f.side_effect = urlfetch.DownloadError try: api_utils._retry_fetch('foo', self.retry_params) self.fail('Should have raised error.') except urlfetch.DownloadError: self.assertEqual(self.max_retries, f.call_count)
def testRetryFailWithResponseTimeOut(self): self.results.extend([urlfetch.DownloadError()] * (self.max_retries - 1)) self.results.append(test_utils.MockUrlFetchResult(httplib.REQUEST_TIMEOUT, None, None)) with mock.patch.object(api_utils.urlfetch, 'fetch') as f: f.side_effect = self._SideEffect self.assertEqual( httplib.REQUEST_TIMEOUT, api_utils._retry_fetch('foo', self.retry_params).status_code)
def testRetryFailWithResponseTimeOut(self): self.results.extend([urlfetch.DownloadError()] * (self.max_retries - 1)) self.results.append( test_utils.MockUrlFetchResult(httplib.REQUEST_TIMEOUT, None, None)) with mock.patch.object(api_utils.urlfetch, 'fetch') as f: f.side_effect = self._SideEffect self.assertEqual( httplib.REQUEST_TIMEOUT, api_utils._retry_fetch('foo', self.retry_params).status_code)
def testRetrySuccess(self): self.results.append(test_utils.MockUrlFetchResult(httplib.REQUEST_TIMEOUT, None, None)) self.results.append(test_utils.MockUrlFetchResult( httplib.SERVICE_UNAVAILABLE, None, None)) self.results.append(urlfetch.DownloadError()) self.results.append(apiproxy_errors.Error()) self.results.append(test_utils.MockUrlFetchResult(httplib.ACCEPTED, None, None)) with mock.patch.object(api_utils.urlfetch, 'fetch') as f: f.side_effect = self._SideEffect self.assertEqual(httplib.ACCEPTED, api_utils._retry_fetch('foo', self.retry_params, deadline=1000).status_code) self.assertEqual(1000, f.call_args[1]['deadline'])
def testRetrySuccess(self): self.results.append( test_utils.MockUrlFetchResult(httplib.REQUEST_TIMEOUT, None, None)) self.results.append( test_utils.MockUrlFetchResult(httplib.SERVICE_UNAVAILABLE, None, None)) self.results.append(urlfetch.DownloadError()) self.results.append(apiproxy_errors.Error()) self.results.append( test_utils.MockUrlFetchResult(httplib.ACCEPTED, None, None)) with mock.patch.object(api_utils.urlfetch, 'fetch') as f: f.side_effect = self._SideEffect self.assertEqual( httplib.ACCEPTED, api_utils._retry_fetch('foo', self.retry_params, deadline=1000).status_code) self.assertEqual(1000, f.call_args[1]['deadline'])
def testNoRetry(self): retry_params = api_utils.RetryParams(max_retries=0) self.assertEqual(None, api_utils._retry_fetch('foo', retry_params))