def test_attempt_number_is_correct_for_interleaved_coroutines(self): attempts = [] def after(retry_state): attempts.append((retry_state.args[0], retry_state.attempt_number)) thing1 = NoIOErrorAfterCount(3) thing2 = NoIOErrorAfterCount(3) future1 = asyncio.ensure_future( _retryable_coroutine.retry_with(after=after)(thing1)) future2 = asyncio.ensure_future( _retryable_coroutine.retry_with(after=after)(thing2)) yield from asyncio.gather(future1, future2) # There's no waiting on retry, only a wait in the coroutine, so the # executions should be interleaved. thing1_attempts = attempts[::2] things1, attempt_nos1 = zip(*thing1_attempts) assert all(thing is thing1 for thing in things1) assert list(attempt_nos1) == [1, 2, 3] thing2_attempts = attempts[1::2] things2, attempt_nos2 = zip(*thing2_attempts) assert all(thing is thing2 for thing in things2) assert list(attempt_nos2) == [1, 2, 3]
async def test_attempt_number_is_correct_for_interleaved_coroutines(self): attempts = [] def after(retry_state): attempts.append((retry_state.args[0], retry_state.attempt_number)) thing1 = NoIOErrorAfterCount(3) thing2 = NoIOErrorAfterCount(3) await asyncio.gather( _retryable_coroutine.retry_with(after=after)(thing1), _retryable_coroutine.retry_with(after=after)(thing2)) # There's no waiting on retry, only a wait in the coroutine, so the # executions should be interleaved. even_thing_attempts = attempts[::2] things, attempt_nos1 = zip(*even_thing_attempts) assert len(set(things)) == 1 assert list(attempt_nos1) == [1, 2, 3] odd_thing_attempts = attempts[1::2] things, attempt_nos2 = zip(*odd_thing_attempts) assert len(set(things)) == 1 assert list(attempt_nos2) == [1, 2, 3]
def test_stop_after_attempt(self): assert gen.is_coroutine_function(_retryable_coroutine) thing = NoIOErrorAfterCount(2) try: yield _retryable_coroutine_with_2_attempts(thing) except RetryError: assert thing.counter == 2
def test_stop_after_attempt(self): assert asyncio.iscoroutinefunction( _retryable_coroutine_with_2_attempts) thing = NoIOErrorAfterCount(2) try: yield from _retryable_coroutine_with_2_attempts(thing) except RetryError: assert thing.counter == 2
def test_retry(self): assert gen.is_coroutine_function(_retryable_coroutine) thing = NoIOErrorAfterCount(5) yield _retryable_coroutine(thing) assert thing.counter == thing.count
async def test_stop_after_attempt(self): thing = NoIOErrorAfterCount(2) try: await _retryable_coroutine_with_2_attempts(thing) except RetryError: assert thing.counter == 2
async def test_retry_using_async_retying(self): thing = NoIOErrorAfterCount(5) retrying = AsyncRetrying() await retrying(_async_function, thing) assert thing.counter == thing.count
async def test_retry(self): thing = NoIOErrorAfterCount(5) await _retryable_coroutine(thing) assert thing.counter == thing.count
def test_retry(self): assert asyncio.iscoroutinefunction(_retryable_coroutine) thing = NoIOErrorAfterCount(5) yield from _retryable_coroutine(thing) assert thing.counter == thing.count
async def test_retry_using_async_retying_legacy_method(self): thing = NoIOErrorAfterCount(5) retrying = AsyncRetrying() with pytest.warns(DeprecationWarning): await retrying.call(_async_function, thing) assert thing.counter == thing.count