Skip to content

Commit

Permalink
Add a non-random test to test_stagger.py.
Browse files Browse the repository at this point in the history
This test fails, but not very reliably.
The cause of failure is that `asyncio.wait_for` sometimes swallows cancellation:
python/cpython#86296
  • Loading branch information
twisteroidambassador committed Oct 17, 2022
1 parent f1b6c24 commit 05eb6de
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions async_stagger/test_stagger.py
Expand Up @@ -14,6 +14,30 @@
from .aitertools import aiter_from_iter


@pytest.mark.asyncio
async def test_simultaneous_done_fail():
for _ in range(50):
await simultaneous_done_fail()


async def simultaneous_done_fail():
async def first():
await asyncio.sleep(0.3)
return 1

async def second():
await asyncio.sleep(0.1)
raise RuntimeError('2')

async def third():
await asyncio.sleep(0.05)
return 3

coro_fns = aiter_from_iter((first, second, third))

winner_result, winner_idx, exc, aiter_exc = await staggered_race(coro_fns, 0.2)


@pytest.mark.asyncio
async def test_stagger_random_tasks():
for _ in range(10):
Expand Down

0 comments on commit 05eb6de

Please sign in to comment.