From 3d00afb0291bbe3ac4a0988d41459bf8d30e3c30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Cepl?= Date: Tue, 4 Aug 2026 20:52:56 +0200 Subject: [PATCH] test: improve robustness of test_shielded_cancel_sleep_time The `test_shielded_cancel_sleep_time` test was failing on certain architectures (notably ppc64le in the OBS server) because the CPU time consumed during the test window occasionally exceeded the wall-clock duration, leading to false-positive assertions of "CPU spinning". The test is designed to ensure that cancelling a shielded task does not cause the event loop to enter a tight loop (spinning), consuming 100% CPU. However, on high-overhead systems, the combination of context switching and event loop management can push CPU usage slightly above the 1:1 ratio of wall-clock time. Fixes: https://github.com/agronholm/anyio/issues/1263 --- tests/test_taskgroups.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_taskgroups.py b/tests/test_taskgroups.py index d05dc908c..7eb9e5fc3 100644 --- a/tests/test_taskgroups.py +++ b/tests/test_taskgroups.py @@ -1559,7 +1559,7 @@ async def test_shielded_cancel_sleep_time() -> None: """ event = anyio.Event() - hang_time = 0.2 + hang_time = 0.6 async def set_event() -> None: await sleep(hang_time) @@ -1567,7 +1567,7 @@ async def set_event() -> None: async def never_cancel_task() -> None: with CancelScope(shield=True): - await sleep(0.2) + await sleep(0.5) await event.wait() async with create_task_group() as tg: @@ -1578,7 +1578,7 @@ async def never_cancel_task() -> None: tg.cancel_scope.cancel() process_time = time.process_time() - assert (time.process_time() - process_time) < hang_time + assert (time.process_time() - process_time) < hang_time * 1.5 async def test_cancelscope_wrong_exit_order() -> None: