From efcac594c1012470f477785593e7bbfb7bccd334 Mon Sep 17 00:00:00 2001 From: goodboy Date: Fri, 3 Jul 2026 00:06:07 -0400 Subject: [PATCH] Port `test_registrar` off `run_in_actor` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two sites migrated (#477 removal), - `test_trynamic_trio`: donny + gretchen each wait on the *other* to register, so they must run CONCURRENTLY — was two non-blocking `run_in_actor()`s awaited after; now two `to_actor.run()` one-shots scheduled into a local `trio` task-nursery. - the unregister-on-cancel cluster test: its non-streaming branch spawned `run_in_actor(trio.sleep_forever)` purely to keep each subactor alive + registered — a `start_actor()` daemon does that without a "main" task, so the spawn loop collapses to the same `start_actor()` the streaming branch already used. Suite: 16 passed. (this patch was generated in some part by [`claude-code`][claude-code-gh]) [claude-code-gh]: https://github.com/anthropics/claude-code --- tests/discovery/test_registrar.py | 50 +++++++++++++++++-------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/tests/discovery/test_registrar.py b/tests/discovery/test_registrar.py index 73f7e265..7a654116 100644 --- a/tests/discovery/test_registrar.py +++ b/tests/discovery/test_registrar.py @@ -152,23 +152,27 @@ async def test_trynamic_trio( for the directed subs. ''' - async with tractor.open_nursery() as n: + async with ( + tractor.open_nursery() as n, + trio.open_nursery() as tn, + ): print("Alright... Action!") - donny = await n.run_in_actor( - ria_fn, - other_actor='gretchen', - reg_addr=reg_addr, - name='donny', - ) - gretchen = await n.run_in_actor( - ria_fn, - other_actor='donny', - reg_addr=reg_addr, - name='gretchen', - ) - print(await gretchen.result()) - print(await donny.result()) + # donny + gretchen each wait on the *other* to register, so + # they must run CONCURRENTLY — schedule both one-shots into a + # local task-nursery (was two non-blocking `run_in_actor()`s). + async def _direct(this_name: str, other_actor: str): + res = await tractor.to_actor.run( + ria_fn, + an=n, + other_actor=other_actor, + reg_addr=reg_addr, + name=this_name, + ) + print(res) + + tn.start_soon(_direct, 'donny', 'gretchen') + tn.start_soon(_direct, 'gretchen', 'donny') print("CUTTTT CUUTT CUT!!?! Donny!! You're supposed to say...") @@ -270,13 +274,15 @@ async def spawn_and_check_registry( portals = {} for i in range(3): name = f'a{i}' - if with_streaming: - portals[name] = await an.start_actor( - name=name, enable_modules=[__name__]) - - else: # no streaming - portals[name] = await an.run_in_actor( - trio.sleep_forever, name=name) + # a daemon subactor is alive + registered + # without a "main" task; the streaming + # branch below uses the module funcs, the + # non-streaming case just needs it up (was + # `run_in_actor(trio.sleep_forever)`). + portals[name] = await an.start_actor( + name=name, + enable_modules=[__name__], + ) # wait on last actor to come up async with tractor.wait_for_actor(name):