Esempio n. 1
0
 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)
Esempio n. 2
0
 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)
Esempio n. 3
0
 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)
Esempio n. 4
0
 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)
Esempio n. 5
0
 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'])
Esempio n. 6
0
 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'])
Esempio n. 7
0
 def testNoRetry(self):
     retry_params = api_utils.RetryParams(max_retries=0)
     self.assertEqual(None, api_utils._retry_fetch('foo', retry_params))
Esempio n. 8
0
 def testNoRetry(self):
   retry_params = api_utils.RetryParams(max_retries=0)
   self.assertEqual(None, api_utils._retry_fetch('foo', retry_params))