Skip to content

Commit b350aa0

Browse files
committed
Wire reg_addr through infected-asyncio tests
Continues the hygiene pattern from de60167 (cancel tests) into `tests/test_infected_asyncio.py`: many tests here were calling `tractor.open_nursery()` w/o `registry_addrs=[reg_addr]` and thus racing on the default `:1616` registry across sessions. Thread the session-unique `reg_addr` through so leaked or slow-to-teardown subactors from a prior test can't cross-pollute. Deats, - add `registry_addrs=[reg_addr]` to `open_nursery()` calls in suite where missing. - `test_sigint_closes_lifetime_stack`: - add `reg_addr`, `debug_mode`, `start_method` fixture params - `delay` now reads the `debug_mode` param directly instead of calling `tractor.debug_mode()` (fires slightly earlier in the test lifecycle) - sanity assert `if debug_mode: assert tractor.debug_mode()` after nursery open - new print showing SIGINT target (`send_sigint_to` + resolved pid) - catch `trio.TooSlowError` around `ctx.wait_for_result()` and conditionally `pytest.xfail` when `send_sigint_to == 'child' and start_method == 'subint_forkserver'` — the known orphan-SIGINT limitation tracked in `ai/conc-anal/subint_forkserver_orphan_sigint_hang_issue.md` - parametrize id typo fix: `'just_trio_slee'` → `'just_trio_sleep'` (this commit msg was generated in some part by [`claude-code`][claude-code-gh]) [claude-code-gh]: https://github.com/anthropics/claude-code
1 parent d6e70e9 commit b350aa0

1 file changed

Lines changed: 70 additions & 13 deletions

File tree

tests/test_infected_asyncio.py

Lines changed: 70 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ def test_tractor_cancels_aio(
183183
async def main():
184184
async with tractor.open_nursery(
185185
debug_mode=debug_mode,
186+
registry_addrs=[reg_addr],
186187
) as an:
187188
portal = await an.run_in_actor(
188189
asyncio_actor,
@@ -205,11 +206,11 @@ def test_trio_cancels_aio(
205206
206207
'''
207208
async def main():
208-
209+
# cancel the nursery shortly after boot
209210
with trio.move_on_after(1):
210-
# cancel the nursery shortly after boot
211-
212-
async with tractor.open_nursery() as tn:
211+
async with tractor.open_nursery(
212+
registry_addrs=[reg_addr],
213+
) as tn:
213214
await tn.run_in_actor(
214215
asyncio_actor,
215216
target='aio_sleep_forever',
@@ -277,7 +278,9 @@ def test_context_spawns_aio_task_that_errors(
277278
'''
278279
async def main():
279280
with trio.fail_after(1 + delay):
280-
async with tractor.open_nursery() as an:
281+
async with tractor.open_nursery(
282+
registry_addrs=[reg_addr],
283+
) as an:
281284
p = await an.start_actor(
282285
'aio_daemon',
283286
enable_modules=[__name__],
@@ -360,7 +363,9 @@ def test_aio_cancelled_from_aio_causes_trio_cancelled(
360363
async def main():
361364

362365
an: tractor.ActorNursery
363-
async with tractor.open_nursery() as an:
366+
async with tractor.open_nursery(
367+
registry_addrs=[reg_addr],
368+
) as an:
364369
p: tractor.Portal = await an.run_in_actor(
365370
asyncio_actor,
366371
target='aio_cancel',
@@ -569,7 +574,9 @@ def test_basic_interloop_channel_stream(
569574
async def main():
570575
# TODO, figure out min timeout here!
571576
with trio.fail_after(6):
572-
async with tractor.open_nursery() as an:
577+
async with tractor.open_nursery(
578+
registry_addrs=[reg_addr],
579+
) as an:
573580
portal = await an.run_in_actor(
574581
stream_from_aio,
575582
infect_asyncio=True,
@@ -582,9 +589,13 @@ async def main():
582589

583590

584591
# TODO: parametrize the above test and avoid the duplication here?
585-
def test_trio_error_cancels_intertask_chan(reg_addr):
592+
def test_trio_error_cancels_intertask_chan(
593+
reg_addr: tuple[str, int],
594+
):
586595
async def main():
587-
async with tractor.open_nursery() as an:
596+
async with tractor.open_nursery(
597+
registry_addrs=[reg_addr],
598+
) as an:
588599
portal = await an.run_in_actor(
589600
stream_from_aio,
590601
trio_raise_err=True,
@@ -619,6 +630,7 @@ async def main():
619630
async with tractor.open_nursery(
620631
debug_mode=debug_mode,
621632
# enable_stack_on_sig=True,
633+
registry_addrs=[reg_addr],
622634
) as an:
623635
portal = await an.run_in_actor(
624636
stream_from_aio,
@@ -667,6 +679,7 @@ def test_aio_exits_early_relays_AsyncioTaskExited(
667679
async def main():
668680
with trio.fail_after(1 + delay):
669681
async with tractor.open_nursery(
682+
registry_addrs=[reg_addr],
670683
debug_mode=debug_mode,
671684
# enable_stack_on_sig=True,
672685
) as an:
@@ -707,6 +720,7 @@ def test_aio_errors_and_channel_propagates_and_closes(
707720
):
708721
async def main():
709722
async with tractor.open_nursery(
723+
registry_addrs=[reg_addr],
710724
debug_mode=debug_mode,
711725
) as an:
712726
portal = await an.run_in_actor(
@@ -806,6 +820,7 @@ def test_echoserver_detailed_mechanics(
806820
):
807821
async def main():
808822
async with tractor.open_nursery(
823+
registry_addrs=[reg_addr],
809824
debug_mode=debug_mode,
810825
) as an:
811826
p = await an.start_actor(
@@ -984,7 +999,7 @@ async def manage_file(
984999
],
9851000
ids=[
9861001
'bg_aio_task',
987-
'just_trio_slee',
1002+
'just_trio_sleep',
9881003
],
9891004
)
9901005
@pytest.mark.parametrize(
@@ -1000,11 +1015,14 @@ async def manage_file(
10001015
)
10011016
def test_sigint_closes_lifetime_stack(
10021017
tmp_path: Path,
1018+
reg_addr: tuple,
1019+
debug_mode: bool,
1020+
10031021
wait_for_ctx: bool,
10041022
bg_aio_task: bool,
10051023
trio_side_is_shielded: bool,
1006-
debug_mode: bool,
10071024
send_sigint_to: str,
1025+
start_method: str,
10081026
):
10091027
'''
10101028
Ensure that an infected child can use the `Actor.lifetime_stack`
@@ -1014,12 +1032,22 @@ def test_sigint_closes_lifetime_stack(
10141032
'''
10151033
async def main():
10161034

1017-
delay = 999 if tractor.debug_mode() else 1
1035+
delay: float = (
1036+
999
1037+
if debug_mode
1038+
else 1
1039+
)
10181040
try:
10191041
an: tractor.ActorNursery
10201042
async with tractor.open_nursery(
1043+
registry_addrs=[reg_addr],
10211044
debug_mode=debug_mode,
10221045
) as an:
1046+
1047+
# sanity
1048+
if debug_mode:
1049+
assert tractor.debug_mode()
1050+
10231051
p: tractor.Portal = await an.start_actor(
10241052
'file_mngr',
10251053
enable_modules=[__name__],
@@ -1054,6 +1082,10 @@ async def main():
10541082
cpid if send_sigint_to == 'child'
10551083
else os.getpid()
10561084
)
1085+
print(
1086+
f'Sending SIGINT to {send_sigint_to!r}\n'
1087+
f'pid: {pid!r}\n'
1088+
)
10571089
os.kill(
10581090
pid,
10591091
signal.SIGINT,
@@ -1064,13 +1096,37 @@ async def main():
10641096
# timeout should trigger!
10651097
if wait_for_ctx:
10661098
print('waiting for ctx outcome in parent..')
1099+
1100+
if debug_mode:
1101+
assert delay == 999
1102+
10671103
try:
1068-
with trio.fail_after(1 + delay):
1104+
with trio.fail_after(
1105+
1 + delay
1106+
):
10691107
await ctx.wait_for_result()
10701108
except tractor.ContextCancelled as ctxc:
10711109
assert ctxc.canceller == ctx.chan.uid
10721110
raise
10731111

1112+
except trio.TooSlowError:
1113+
if (
1114+
send_sigint_to == 'child'
1115+
and
1116+
start_method == 'subint_forkserver'
1117+
):
1118+
pytest.xfail(
1119+
reason=(
1120+
'SIGINT delivery to fork-child subactor is known '
1121+
'to NOT SUCCEED, precisely bc we have not wired up a'
1122+
'"trio SIGINT mode" in the child pre-fork.\n'
1123+
'Also see `test_orphaned_subactor_sigint_cleanup_DRAFT` for'
1124+
'a dedicated suite demonstrating this expected limitation as '
1125+
'well as the detailed doc:\n'
1126+
'`ai/conc-anal/subint_forkserver_orphan_sigint_hang_issue.md`.\n'
1127+
),
1128+
)
1129+
10741130
# XXX CASE 2: this seems to be the source of the
10751131
# original issue which exhibited BEFORE we put
10761132
# a `Actor.cancel_soon()` inside
@@ -1170,6 +1226,7 @@ async def main():
11701226
with trio.fail_after(3):
11711227
an: tractor.ActorNursery
11721228
async with tractor.open_nursery(
1229+
registry_addrs=[reg_addr],
11731230
debug_mode=debug_mode,
11741231
loglevel=loglevel,
11751232
) as an:

0 commit comments

Comments
 (0)