def test_none_response_when_no_matches(self): delay_function = retryhandler.create_exponential_delay_function( 1, 2) checker = retryhandler.HTTPStatusCodeChecker(500) handler = retryhandler.RetryHandler(checker, delay_function) response = (HTTP_200_RESPONSE, {}) self.assertIsNone(handler(response=response, attempts=1, caught_exception=None))
def test_action_tied_to_policy(self): # When a retry rule matches we should return the # amount of time to sleep, otherwise we should return None. delay_function = retryhandler.create_exponential_delay_function( 1, 2) checker = retryhandler.HTTPStatusCodeChecker(500) handler = retryhandler.RetryHandler(checker, delay_function) response = (HTTP_500_RESPONSE, {}) self.assertEqual( handler(response=response, attempts=1, caught_exception=None), 1) self.assertEqual( handler(response=response, attempts=2, caught_exception=None), 2) self.assertEqual( handler(response=response, attempts=3, caught_exception=None), 4) self.assertEqual( handler(response=response, attempts=4, caught_exception=None), 8)
def __init__(self, config, scale): self._delay = create_exponential_delay_function('rand', 2) self._attempts = 0 self._max_attempts = config.retries.get('max_attempts', RetryHandler.DEFAULT_RETRIES) if config and config.retries \ else RetryHandler.DEFAULT_RETRIES self.scale = scale