def test_should_not_retry_when_there_were_too_many_attempts(self): retry_policy = RetryPolicy(allowed_retries=3) context = Context() context.attempts = 4 assert retry_policy.should_retry(context, Exception()) == (False, None)
def test_should_retry_when_attempts_is_less_then_limit(self): retry_policy = RetryPolicy(allowed_retries=3) context = Context() context.attempts = 3 assert retry_policy.should_retry(context, Exception()) == (True, 0)
def test_should_not_retry_when_exception_is_retriable_but_there_were_too_many_attempts(self): retry_policy = RetryPolicy(allowed_retries=3, retriable_exceptions=[BufferError]) context = Context() context.attempts = 4 assert retry_policy.should_retry(context, BufferError()) is False
def test_should_retry_when_exception_is_retriable(self): retry_policy = RetryPolicy(allowed_retries=3, retriable_exceptions=[BufferError]) context = Context() context.attempts = 3 assert retry_policy.should_retry(context, BufferError()) is True
def test_should_retry_with_more_that_one_exception_type(self): retry_policy = RetryPolicy(allowed_retries=3, retriable_exceptions=[BufferError, ValueError]) context = Context() context.attempts = 3 assert retry_policy.should_retry(context, BufferError()) is True assert retry_policy.should_retry(context, ValueError()) is True
def test_should_not_retry_when_exception_is_not_retriable(self): retry_policy = RetryPolicy(allowed_retries=3, retriable_exceptions=[BufferError]) context = Context() context.attempts = 3 assert retry_policy.should_retry(context, ArithmeticError()) == (False, None)
def __init__(self, retry_policy=None, circuit_breaker=None): if retry_policy is None: retry_policy = RetryPolicy(allowed_retries=0) self.retry_policy = retry_policy if circuit_breaker is None: circuit_breaker = AlwaysClosedCircuitBreaker() self.circuit_breaker = circuit_breaker
def test_should_abort(self): raise_policy = RetryPolicy(abortable_exceptions=[AttributeError]) assert raise_policy.should_abort(BufferError()) is False assert raise_policy.should_abort(AttributeError()) is True