Exemple #1
0
    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)
Exemple #2
0
    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
Exemple #6
0
    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)
Exemple #7
0
    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
Exemple #8
0
 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