From d1fb4a1a26fac583ce6beae5cee92f0a199e63a2 Mon Sep 17 00:00:00 2001 From: goodboy Date: Thu, 2 Jul 2026 19:45:22 -0400 Subject: [PATCH] Add anti-hang `fail_after` cap to aio-cancel test Wrap `test_tractor_cancels_aio`'s `main()` in a `trio.fail_after(9 * cpu_perf_headroom())` so a wedged remote runtime can't hang the test forever. This is the blessed anti-hang guard here bc `pytest-timeout`'s global cap is intentionally off (it breaks `trio` under the fork backends, per the `pyproject` NOTE). The cap is generous + CPU-headroom-scaled bc it's an anti-hang guard, not a perf assertion. Motivated by the `._ria_nursery`-removal regression where a wedged ria-reaper once hung this exact test indefinitely. (this patch was generated in some part by [`claude-code`][claude-code-gh]) [claude-code-gh]: https://github.com/anthropics/claude-code --- tests/test_infected_asyncio.py | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/tests/test_infected_asyncio.py b/tests/test_infected_asyncio.py index bdb1b852..723b327e 100644 --- a/tests/test_infected_asyncio.py +++ b/tests/test_infected_asyncio.py @@ -207,18 +207,27 @@ def test_tractor_cancels_aio( ''' async def main(): - async with tractor.open_nursery( - debug_mode=debug_mode, - registry_addrs=[reg_addr], - ) as an: - portal = await an.run_in_actor( - asyncio_actor, - target='aio_sleep_forever', - expect_err='trio.Cancelled', - infect_asyncio=True, - ) - # cancel the entire remote runtime - await portal.cancel_actor() + # anti-hang wall-clock cap: a per-test `trio.fail_after` + # is the blessed guard here since `pytest-timeout`'s + # global cap is intentionally off (see the `pyproject` + # NOTE — it breaks trio under fork backends). Generous + + # CPU-headroom-scaled bc this is an anti-hang guard, not + # a perf assertion; a wedged ria-reaper once hung this + # test forever (the `._ria_nursery`-removal regression). + from .conftest import cpu_perf_headroom + with trio.fail_after(9 * cpu_perf_headroom()): + async with tractor.open_nursery( + debug_mode=debug_mode, + registry_addrs=[reg_addr], + ) as an: + portal = await an.run_in_actor( + asyncio_actor, + target='aio_sleep_forever', + expect_err='trio.Cancelled', + infect_asyncio=True, + ) + # cancel the entire remote runtime + await portal.cancel_actor() trio.run(main)