From 05eb6dec47d2bedc5c5b1edc83b35e579aa44f0e Mon Sep 17 00:00:00 2001 From: twisteroid ambassador Date: Tue, 18 Oct 2022 03:06:05 +0800 Subject: [PATCH] Add a non-random test to test_stagger.py. This test fails, but not very reliably. The cause of failure is that `asyncio.wait_for` sometimes swallows cancellation: https://github.com/python/cpython/issues/86296 --- async_stagger/test_stagger.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/async_stagger/test_stagger.py b/async_stagger/test_stagger.py index 6d46cab..4e0ad73 100644 --- a/async_stagger/test_stagger.py +++ b/async_stagger/test_stagger.py @@ -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):