def do_request_async(self, url, method='GET', headers=None, payload=None, deadline=None, callback=None): """Issue one HTTP request. It performs async retries using tasklets. Args: url: the url to fetch. method: the method in which to fetch. headers: the http headers. payload: the data to submit in the fetch. deadline: the deadline in which to make the call. callback: the call to make once completed. Yields: The async fetch of the url. """ retry_wrapper = api_utils._RetryWrapper( self.retry_params, retriable_exceptions=api_utils._RETRIABLE_EXCEPTIONS, should_retry=api_utils._should_retry) resp = yield retry_wrapper.run( self.urlfetch_async, url=url, method=method, headers=headers, payload=payload, deadline=deadline, callback=callback, follow_redirects=False) raise ndb.Return((resp.status_code, resp.headers, resp.content))
def testTooLittleRetry(self): fut = api_utils._RetryWrapper(api_utils.RetryParams(min_retries=0, max_retries=1), retriable_exceptions=(ValueError, )).run( self.tasklet_for_test, results=[ValueError, ValueError]) self.assertRaises(ValueError, fut.get_result)
def testRetryReturnedABadResult(self): fut = api_utils._RetryWrapper( api_utils.RetryParams(min_retries=1, max_retries=3), should_retry=lambda r: r < 0).run( self.tasklet_for_test, results=[-1, -1, -1, -1]) r = fut.get_result() self.assertEqual(-1, r)
def testTooLittleRetry(self): fut = api_utils._RetryWrapper( api_utils.RetryParams(min_retries=0, max_retries=1), retriable_exceptions=(ValueError,)).run( self.tasklet_for_test, results=[ValueError, ValueError]) self.assertRaises(ValueError, fut.get_result)
def do_request_async(self, url, method='GET', headers=None, payload=None, deadline=None, callback=None): """Issue one HTTP request. It performs async retries using tasklets. Args: url: the url to fetch. method: the method in which to fetch. headers: the http headers. payload: the data to submit in the fetch. deadline: the deadline in which to make the call. callback: the call to make once completed. Yields: The async fetch of the url. """ retry_wrapper = api_utils._RetryWrapper( self.retry_params, retriable_exceptions=api_utils._RETRIABLE_EXCEPTIONS, should_retry=api_utils._should_retry) resp = yield retry_wrapper.run(self.urlfetch_async, url=url, method=method, headers=headers, payload=payload, deadline=deadline, callback=callback, follow_redirects=False) raise ndb.Return((resp.status_code, resp.headers, resp.content))
def testRetryDueToError(self): fut = api_utils._RetryWrapper( api_utils.RetryParams(min_retries=1, max_retries=3), retriable_exceptions=(ValueError, )).run( self.tasklet_for_test, results=[ValueError, ValueError, ValueError, 1]) r = fut.get_result() self.assertEqual(1, r)
def testRetryReturnedABadResult(self): fut = api_utils._RetryWrapper(api_utils.RetryParams(min_retries=1, max_retries=3), should_retry=lambda r: r < 0).run( self.tasklet_for_test, results=[-1, -1, -1, -1]) r = fut.get_result() self.assertEqual(-1, r)
def testRetryDueToError(self): fut = api_utils._RetryWrapper( api_utils.RetryParams(min_retries=1, max_retries=3), retriable_exceptions=(ValueError,)).run( self.tasklet_for_test, results=[ValueError, ValueError, ValueError, 1]) r = fut.get_result() self.assertEqual(1, r)
def testRetryDueToTransientError(self): results = [urlfetch.DownloadError, apiproxy_errors.Error, app_identity.InternalError, app_identity.BackendDeadlineExceeded, urlfetch_errors.InternalTransientError, 1] fut = api_utils._RetryWrapper( api_utils.RetryParams(min_retries=1, max_retries=len(results)), retriable_exceptions=api_utils._RETRIABLE_EXCEPTIONS).run( self.tasklet_for_test, results=results) r = fut.get_result() self.assertEqual(1, r)
def testRetryDueToTransientError(self): results = [ urlfetch.DownloadError, apiproxy_errors.Error, app_identity.InternalError, app_identity.BackendDeadlineExceeded, urlfetch_errors.InternalTransientError, 1 ] fut = api_utils._RetryWrapper( api_utils.RetryParams(min_retries=1, max_retries=len(results)), retriable_exceptions=api_utils._RETRIABLE_EXCEPTIONS).run( self.tasklet_for_test, results=results) r = fut.get_result() self.assertEqual(1, r)
def testNoRetryDueToRetryParams(self): retry_params = api_utils.RetryParams(min_retries=0, max_retries=0) fut = api_utils._RetryWrapper(retry_params, retriable_exceptions=[ValueError]).run( test_tasklet3, a=1) self.assertRaises(ValueError, fut.get_result)
def testTaskletWasSuccessful(self): fut = api_utils._RetryWrapper(api_utils.RetryParams()).run( test_tasklet1, a=1, b=2) a, b = fut.get_result() self.assertEqual(1, a) self.assertEqual(2, b)
def testNoRetryDueToErrorType(self): fut = api_utils._RetryWrapper( api_utils.RetryParams(), retriable_exceptions=[TypeError]).run( test_tasklet3, a=1) self.assertRaises(ValueError, fut.get_result)
def testNoRetryDueToRetryParams(self): retry_params = api_utils.RetryParams(min_retries=0, max_retries=0) fut = api_utils._RetryWrapper( retry_params, retriable_exceptions=[ValueError]).run( test_tasklet3, a=1) self.assertRaises(ValueError, fut.get_result)
def testNoRetryDueToErrorType(self): fut = api_utils._RetryWrapper(api_utils.RetryParams(), retriable_exceptions=[TypeError]).run( test_tasklet3, a=1) self.assertRaises(ValueError, fut.get_result)
def testRuntimeError(self): fut = api_utils._RetryWrapper( api_utils.RetryParams()).run(test_tasklet4) self.assertRaises(runtime.DeadlineExceededError, fut.get_result)