def test_callback_prevents_others(test_app, coroutine): """Test that the callback blocks other callbacks.""" test_app.settings['RETRY_CALLBACK'] = coroutine retry.Retry(test_app) with pytest.raises(Abort): for cb in test_app._callbacks['error']: yield from cb(test_app, {}, retry.RetryableException())
async def test_callback_exceeds_timeout(test_app, coroutine): """Test that callback doesn't run when the timeout is exceeded.""" # Create a function that sets a flag indicating it's been called. original_callback_called = False @test_app.error async def original_callback(*args): nonlocal original_callback_called original_callback_called = True test_app.settings['RETRY_CALLBACK'] = coroutine test_app.settings['RETRY_TIMEOUT'] = 0 for cb in test_app._callbacks['error']: await cb(test_app, {}, retry.RetryableException()) assert original_callback_called
def test_callback_exceeds_threshold(test_app, coroutine): """Test that callback doesn't run when the threshold is exceeded.""" # Create a function that sets a flag indicating it's been called. original_callback_called = False @test_app.error @asyncio.coroutine def original_callback(*args): nonlocal original_callback_called original_callback_called = True test_app.settings['RETRY_CALLBACK'] = coroutine test_app.settings['RETRY_THRESHOLD'] = 0 for cb in test_app._callbacks['error']: yield from cb(test_app, {}, retry.RetryableException()) assert original_callback_called
async def test_delay(monkeypatch, test_app, coroutine): """Test that retry delays.""" sleep_called = False test_app.settings['RETRY_CALLBACK'] = coroutine test_app.settings['RETRY_DELAY'] = 1 retry.Retry(test_app) async def sleep(duration): nonlocal sleep_called sleep_called = True monkeypatch.setattr(asyncio, 'sleep', sleep) with suppress(Abort): await retry._retry(test_app, {}, retry.RetryableException()) assert sleep_called