From 7458f99733c844309f40baa5d2e437de7c33f7ce Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Fri, 8 Mar 2024 15:34:20 -0500 Subject: [PATCH] Add a `._state._runtime_vars['_registry_addrs']` Such that it's set to whatever `Actor.reg_addrs: list[tuple]` is during the actor's init-after-spawn guaranteeing each actor has at least the registry infos from its parent. Ensure we read this if defined over `_root._default_lo_addrs` in `._discovery` routines, namely `.find_actor()` since it's the one API normally used without expecting the runtime's `current_actor()` to be up. Update the latest inter-peer cancellation test to use the `reg_addr` fixture (and thus test this new runtime-vars value via `find_actor()` usage) since it was failing if run *after* the infected `asyncio` suite due to registry contact failure. --- tests/test_inter_peer_cancellation.py | 2 ++ tractor/_discovery.py | 11 +++++++++-- tractor/_runtime.py | 9 +++++---- tractor/_state.py | 3 ++- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/tests/test_inter_peer_cancellation.py b/tests/test_inter_peer_cancellation.py index c3d9e4f..e3c8a7d 100644 --- a/tests/test_inter_peer_cancellation.py +++ b/tests/test_inter_peer_cancellation.py @@ -939,6 +939,7 @@ async def tell_little_bro( def test_peer_spawns_and_cancels_service_subactor( debug_mode: bool, raise_client_error: str, + reg_addr: tuple[str, int], ): # NOTE: this tests for the modden `mod wks open piker` bug # discovered as part of implementing workspace ctx @@ -956,6 +957,7 @@ def test_peer_spawns_and_cancels_service_subactor( async with tractor.open_nursery( # NOTE: to halt the peer tasks on ctxc, uncomment this. debug_mode=debug_mode, + registry_addrs=[reg_addr], ) as an: server: Portal = await an.start_actor( (server_name := 'spawn_server'), diff --git a/tractor/_discovery.py b/tractor/_discovery.py index 8cccc50..de79edc 100644 --- a/tractor/_discovery.py +++ b/tractor/_discovery.py @@ -35,7 +35,10 @@ from ._portal import ( open_portal, LocalPortal, ) -from ._state import current_actor, _runtime_vars +from ._state import ( + current_actor, + _runtime_vars, +) if TYPE_CHECKING: @@ -205,7 +208,11 @@ async def find_actor( # every call since something may change it globally (eg. # like in our discovery test suite)! from . import _root - registry_addrs = _root._default_lo_addrs + registry_addrs = ( + _runtime_vars['_registry_addrs'] + or + _root._default_lo_addrs + ) maybe_portals: list[ AsyncContextManager[tuple[str, int]] diff --git a/tractor/_runtime.py b/tractor/_runtime.py index 09778c7..607f98c 100644 --- a/tractor/_runtime.py +++ b/tractor/_runtime.py @@ -811,10 +811,10 @@ class Actor: name: str, *, enable_modules: list[str] = [], - uid: str | None = None, - loglevel: str | None = None, - registry_addrs: list[tuple[str, int]] | None = None, - spawn_method: str | None = None, + uid: str|None = None, + loglevel: str|None = None, + registry_addrs: list[tuple[str, int]]|None = None, + spawn_method: str|None = None, # TODO: remove! arbiter_addr: tuple[str, int] | None = None, @@ -896,6 +896,7 @@ class Actor: self._reg_addrs: list[tuple[str, int]] = [] if registry_addrs: self.reg_addrs: list[tuple[str, int]] = registry_addrs + _state._runtime_vars['_registry_addrs'] = registry_addrs @property def reg_addrs(self) -> list[tuple[str, int]]: diff --git a/tractor/_state.py b/tractor/_state.py index f391743..9e4e947 100644 --- a/tractor/_state.py +++ b/tractor/_state.py @@ -33,7 +33,8 @@ _last_actor_terminated: Actor|None = None _runtime_vars: dict[str, Any] = { '_debug_mode': False, '_is_root': False, - '_root_mailbox': (None, None) + '_root_mailbox': (None, None), + '_registry_addrs': [], }