def test_get_retry_exception_returns(): strategy = retry_module.RetryStrategy(max_attempts=10, wait=5.0) now = pendulum.datetime(2000, 1, 1, tz="UTC") expected = pendulum.datetime(2000, 1, 1, 0, 0, 5, tz="UTC") with pendulum.test(now): exc = strategy.get_retry_exception(exception=None, attempts=1) assert isinstance(exc, exceptions.JobRetry) assert exc.scheduled_at == expected
def test_get_retry_exception_returns(): strategy = retry_module.RetryStrategy(max_attempts=10, wait=5.0) now = utils.utcnow() expected = now + datetime.timedelta(seconds=5, microseconds=0) exc = strategy.get_retry_exception(exception=None, attempts=1) assert isinstance(exc, exceptions.JobRetry) assert exc.scheduled_at == expected.replace(microsecond=0)
def test_get_schedule_in(attempts, schedule_in, wait, linear_wait, exponential_wait): strategy = retry_module.RetryStrategy( max_attempts=10, wait=wait, linear_wait=linear_wait, exponential_wait=exponential_wait, ) assert strategy.get_schedule_in(attempts=attempts) == schedule_in
def test_get_retry_exception_returns_none(): strategy = retry_module.RetryStrategy(max_attempts=10, wait=5.0) assert strategy.get_retry_exception(exception=None, attempts=100) is None
def test_get_schedule_in_exception(exception, expected): strategy = retry_module.RetryStrategy(retry_exceptions=[ValueError]) assert strategy.get_schedule_in(exception=exception, attempts=0) == expected
import pendulum import pytest from procrastinate import exceptions from procrastinate import retry as retry_module @pytest.mark.parametrize( "retry, expected_strategy", [ (None, None), (12, retry_module.RetryStrategy(max_attempts=12)), (True, retry_module.RetryStrategy()), ( retry_module.RetryStrategy(max_attempts=42), retry_module.RetryStrategy(max_attempts=42), ), ], ) def test_get_retry_strategy(retry, expected_strategy): assert expected_strategy == retry_module.get_retry_strategy(retry) @pytest.mark.parametrize( "attempts, wait, linear_wait, exponential_wait, schedule_in", [ # No wait (0, 0.0, 0.0, 0.0, 0.0), # Constant, first try (1, 5.0, 0.0, 0.0, 5.0), # Constant, last try