Ejemplo n.º 1
0
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())
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
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