2018-06-07 04:29:17 +00:00
|
|
|
"""
|
Rename `Arbiter` -> `Registrar`, mv to `discovery._registry`
Move the `Arbiter` class out of `runtime._runtime` into its
logical home at `discovery._registry` as `Registrar(Actor)`.
This completes the long-standing terminology migration from
"arbiter" to "registrar/registry" throughout the codebase.
Deats,
- add new `discovery/_registry.py` mod with `Registrar`
class + backward-compat `Arbiter = Registrar` alias.
- rename `Actor.is_arbiter` attr -> `.is_registrar`;
old attr now a `@property` with `DeprecationWarning`.
- `_root.py` imports `Registrar` directly for
root-actor instantiation.
- export `Registrar` + `Arbiter` from `tractor.__init__`.
- `_runtime.py` re-imports from `discovery._registry`
for backward compat.
Also,
- update all test files to use `.is_registrar`
(`test_local`, `test_rpc`, `test_spawning`,
`test_discovery`, `test_multi_program`).
- update "arbiter" -> "registrar" in comments/docstrings
across `_discovery.py`, `_server.py`, `_transport.py`,
`_testing/pytest.py`, and examples.
- drop resolved TODOs from `_runtime.py` and `_root.py`.
(this patch was generated in some part by [`claude-code`][claude-code-gh])
[claude-code-gh]: https://github.com/anthropics/claude-code
2026-03-23 22:56:21 +00:00
|
|
|
Registrar and "local" actor api
|
2018-06-07 04:29:17 +00:00
|
|
|
"""
|
2018-06-12 19:23:58 +00:00
|
|
|
import time
|
|
|
|
|
|
2018-06-07 04:29:17 +00:00
|
|
|
import pytest
|
2018-06-12 19:23:58 +00:00
|
|
|
import trio
|
2018-07-05 23:49:21 +00:00
|
|
|
import tractor
|
2018-06-07 04:29:17 +00:00
|
|
|
|
2024-03-12 19:48:20 +00:00
|
|
|
from tractor._testing import tractor_test
|
2018-09-05 22:13:23 +00:00
|
|
|
|
|
|
|
|
|
2018-06-12 19:23:58 +00:00
|
|
|
@pytest.mark.trio
|
2022-10-10 23:15:39 +00:00
|
|
|
async def test_no_runtime():
|
Rename `Arbiter` -> `Registrar`, mv to `discovery._registry`
Move the `Arbiter` class out of `runtime._runtime` into its
logical home at `discovery._registry` as `Registrar(Actor)`.
This completes the long-standing terminology migration from
"arbiter" to "registrar/registry" throughout the codebase.
Deats,
- add new `discovery/_registry.py` mod with `Registrar`
class + backward-compat `Arbiter = Registrar` alias.
- rename `Actor.is_arbiter` attr -> `.is_registrar`;
old attr now a `@property` with `DeprecationWarning`.
- `_root.py` imports `Registrar` directly for
root-actor instantiation.
- export `Registrar` + `Arbiter` from `tractor.__init__`.
- `_runtime.py` re-imports from `discovery._registry`
for backward compat.
Also,
- update all test files to use `.is_registrar`
(`test_local`, `test_rpc`, `test_spawning`,
`test_discovery`, `test_multi_program`).
- update "arbiter" -> "registrar" in comments/docstrings
across `_discovery.py`, `_server.py`, `_transport.py`,
`_testing/pytest.py`, and examples.
- drop resolved TODOs from `_runtime.py` and `_root.py`.
(this patch was generated in some part by [`claude-code`][claude-code-gh])
[claude-code-gh]: https://github.com/anthropics/claude-code
2026-03-23 22:56:21 +00:00
|
|
|
"""A registrar must be established before any nurseries
|
2018-06-12 19:23:58 +00:00
|
|
|
can be created.
|
|
|
|
|
|
Rename `Arbiter` -> `Registrar`, mv to `discovery._registry`
Move the `Arbiter` class out of `runtime._runtime` into its
logical home at `discovery._registry` as `Registrar(Actor)`.
This completes the long-standing terminology migration from
"arbiter" to "registrar/registry" throughout the codebase.
Deats,
- add new `discovery/_registry.py` mod with `Registrar`
class + backward-compat `Arbiter = Registrar` alias.
- rename `Actor.is_arbiter` attr -> `.is_registrar`;
old attr now a `@property` with `DeprecationWarning`.
- `_root.py` imports `Registrar` directly for
root-actor instantiation.
- export `Registrar` + `Arbiter` from `tractor.__init__`.
- `_runtime.py` re-imports from `discovery._registry`
for backward compat.
Also,
- update all test files to use `.is_registrar`
(`test_local`, `test_rpc`, `test_spawning`,
`test_discovery`, `test_multi_program`).
- update "arbiter" -> "registrar" in comments/docstrings
across `_discovery.py`, `_server.py`, `_transport.py`,
`_testing/pytest.py`, and examples.
- drop resolved TODOs from `_runtime.py` and `_root.py`.
(this patch was generated in some part by [`claude-code`][claude-code-gh])
[claude-code-gh]: https://github.com/anthropics/claude-code
2026-03-23 22:56:21 +00:00
|
|
|
(In other words ``tractor.open_root_actor()`` must be
|
|
|
|
|
engaged at some point?)
|
2018-06-12 19:23:58 +00:00
|
|
|
"""
|
2022-10-10 23:15:39 +00:00
|
|
|
with pytest.raises(RuntimeError) :
|
|
|
|
|
async with tractor.find_actor('doggy'):
|
2018-06-12 19:23:58 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
2018-09-21 04:32:23 +00:00
|
|
|
@tractor_test
|
2025-03-20 21:50:22 +00:00
|
|
|
async def test_self_is_registered(reg_addr):
|
Rename `Arbiter` -> `Registrar`, mv to `discovery._registry`
Move the `Arbiter` class out of `runtime._runtime` into its
logical home at `discovery._registry` as `Registrar(Actor)`.
This completes the long-standing terminology migration from
"arbiter" to "registrar/registry" throughout the codebase.
Deats,
- add new `discovery/_registry.py` mod with `Registrar`
class + backward-compat `Arbiter = Registrar` alias.
- rename `Actor.is_arbiter` attr -> `.is_registrar`;
old attr now a `@property` with `DeprecationWarning`.
- `_root.py` imports `Registrar` directly for
root-actor instantiation.
- export `Registrar` + `Arbiter` from `tractor.__init__`.
- `_runtime.py` re-imports from `discovery._registry`
for backward compat.
Also,
- update all test files to use `.is_registrar`
(`test_local`, `test_rpc`, `test_spawning`,
`test_discovery`, `test_multi_program`).
- update "arbiter" -> "registrar" in comments/docstrings
across `_discovery.py`, `_server.py`, `_transport.py`,
`_testing/pytest.py`, and examples.
- drop resolved TODOs from `_runtime.py` and `_root.py`.
(this patch was generated in some part by [`claude-code`][claude-code-gh])
[claude-code-gh]: https://github.com/anthropics/claude-code
2026-03-23 22:56:21 +00:00
|
|
|
"Verify waiting on the registrar to register itself using the standard api."
|
2018-09-21 04:32:23 +00:00
|
|
|
actor = tractor.current_actor()
|
Rename `Arbiter` -> `Registrar`, mv to `discovery._registry`
Move the `Arbiter` class out of `runtime._runtime` into its
logical home at `discovery._registry` as `Registrar(Actor)`.
This completes the long-standing terminology migration from
"arbiter" to "registrar/registry" throughout the codebase.
Deats,
- add new `discovery/_registry.py` mod with `Registrar`
class + backward-compat `Arbiter = Registrar` alias.
- rename `Actor.is_arbiter` attr -> `.is_registrar`;
old attr now a `@property` with `DeprecationWarning`.
- `_root.py` imports `Registrar` directly for
root-actor instantiation.
- export `Registrar` + `Arbiter` from `tractor.__init__`.
- `_runtime.py` re-imports from `discovery._registry`
for backward compat.
Also,
- update all test files to use `.is_registrar`
(`test_local`, `test_rpc`, `test_spawning`,
`test_discovery`, `test_multi_program`).
- update "arbiter" -> "registrar" in comments/docstrings
across `_discovery.py`, `_server.py`, `_transport.py`,
`_testing/pytest.py`, and examples.
- drop resolved TODOs from `_runtime.py` and `_root.py`.
(this patch was generated in some part by [`claude-code`][claude-code-gh])
[claude-code-gh]: https://github.com/anthropics/claude-code
2026-03-23 22:56:21 +00:00
|
|
|
assert actor.is_registrar
|
2021-01-09 01:40:49 +00:00
|
|
|
with trio.fail_after(0.2):
|
|
|
|
|
async with tractor.wait_for_actor('root') as portal:
|
|
|
|
|
assert portal.channel.uid[0] == 'root'
|
2018-09-21 04:32:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@tractor_test
|
2025-03-20 21:50:22 +00:00
|
|
|
async def test_self_is_registered_localportal(reg_addr):
|
Rename `Arbiter` -> `Registrar`, mv to `discovery._registry`
Move the `Arbiter` class out of `runtime._runtime` into its
logical home at `discovery._registry` as `Registrar(Actor)`.
This completes the long-standing terminology migration from
"arbiter" to "registrar/registry" throughout the codebase.
Deats,
- add new `discovery/_registry.py` mod with `Registrar`
class + backward-compat `Arbiter = Registrar` alias.
- rename `Actor.is_arbiter` attr -> `.is_registrar`;
old attr now a `@property` with `DeprecationWarning`.
- `_root.py` imports `Registrar` directly for
root-actor instantiation.
- export `Registrar` + `Arbiter` from `tractor.__init__`.
- `_runtime.py` re-imports from `discovery._registry`
for backward compat.
Also,
- update all test files to use `.is_registrar`
(`test_local`, `test_rpc`, `test_spawning`,
`test_discovery`, `test_multi_program`).
- update "arbiter" -> "registrar" in comments/docstrings
across `_discovery.py`, `_server.py`, `_transport.py`,
`_testing/pytest.py`, and examples.
- drop resolved TODOs from `_runtime.py` and `_root.py`.
(this patch was generated in some part by [`claude-code`][claude-code-gh])
[claude-code-gh]: https://github.com/anthropics/claude-code
2026-03-23 22:56:21 +00:00
|
|
|
"Verify waiting on the registrar to register itself using a local portal."
|
2018-09-21 04:32:23 +00:00
|
|
|
actor = tractor.current_actor()
|
Rename `Arbiter` -> `Registrar`, mv to `discovery._registry`
Move the `Arbiter` class out of `runtime._runtime` into its
logical home at `discovery._registry` as `Registrar(Actor)`.
This completes the long-standing terminology migration from
"arbiter" to "registrar/registry" throughout the codebase.
Deats,
- add new `discovery/_registry.py` mod with `Registrar`
class + backward-compat `Arbiter = Registrar` alias.
- rename `Actor.is_arbiter` attr -> `.is_registrar`;
old attr now a `@property` with `DeprecationWarning`.
- `_root.py` imports `Registrar` directly for
root-actor instantiation.
- export `Registrar` + `Arbiter` from `tractor.__init__`.
- `_runtime.py` re-imports from `discovery._registry`
for backward compat.
Also,
- update all test files to use `.is_registrar`
(`test_local`, `test_rpc`, `test_spawning`,
`test_discovery`, `test_multi_program`).
- update "arbiter" -> "registrar" in comments/docstrings
across `_discovery.py`, `_server.py`, `_transport.py`,
`_testing/pytest.py`, and examples.
- drop resolved TODOs from `_runtime.py` and `_root.py`.
(this patch was generated in some part by [`claude-code`][claude-code-gh])
[claude-code-gh]: https://github.com/anthropics/claude-code
2026-03-23 22:56:21 +00:00
|
|
|
assert actor.is_registrar
|
2025-03-23 03:14:04 +00:00
|
|
|
async with tractor.get_registry(reg_addr) as portal:
|
2026-03-23 22:44:14 +00:00
|
|
|
assert isinstance(portal, tractor.runtime._portal.LocalPortal)
|
2021-01-09 01:40:49 +00:00
|
|
|
|
|
|
|
|
with trio.fail_after(0.2):
|
2021-02-24 19:59:48 +00:00
|
|
|
sockaddr = await portal.run_from_ns(
|
|
|
|
|
'self', 'wait_for_actor', name='root')
|
2025-03-20 21:50:22 +00:00
|
|
|
assert sockaddr[0] == reg_addr
|
2018-09-21 04:32:23 +00:00
|
|
|
|
|
|
|
|
|
2025-03-20 21:50:22 +00:00
|
|
|
def test_local_actor_async_func(reg_addr):
|
2018-06-12 19:23:58 +00:00
|
|
|
"""Verify a simple async function in-process.
|
|
|
|
|
"""
|
2018-06-19 15:49:25 +00:00
|
|
|
nums = []
|
|
|
|
|
|
|
|
|
|
async def print_loop():
|
|
|
|
|
|
2021-02-24 19:59:48 +00:00
|
|
|
async with tractor.open_root_actor(
|
2025-03-20 21:50:22 +00:00
|
|
|
registry_addrs=[reg_addr],
|
2021-02-24 19:59:48 +00:00
|
|
|
):
|
Rename `Arbiter` -> `Registrar`, mv to `discovery._registry`
Move the `Arbiter` class out of `runtime._runtime` into its
logical home at `discovery._registry` as `Registrar(Actor)`.
This completes the long-standing terminology migration from
"arbiter" to "registrar/registry" throughout the codebase.
Deats,
- add new `discovery/_registry.py` mod with `Registrar`
class + backward-compat `Arbiter = Registrar` alias.
- rename `Actor.is_arbiter` attr -> `.is_registrar`;
old attr now a `@property` with `DeprecationWarning`.
- `_root.py` imports `Registrar` directly for
root-actor instantiation.
- export `Registrar` + `Arbiter` from `tractor.__init__`.
- `_runtime.py` re-imports from `discovery._registry`
for backward compat.
Also,
- update all test files to use `.is_registrar`
(`test_local`, `test_rpc`, `test_spawning`,
`test_discovery`, `test_multi_program`).
- update "arbiter" -> "registrar" in comments/docstrings
across `_discovery.py`, `_server.py`, `_transport.py`,
`_testing/pytest.py`, and examples.
- drop resolved TODOs from `_runtime.py` and `_root.py`.
(this patch was generated in some part by [`claude-code`][claude-code-gh])
[claude-code-gh]: https://github.com/anthropics/claude-code
2026-03-23 22:56:21 +00:00
|
|
|
# registrar is started in-proc if dne
|
|
|
|
|
assert tractor.current_actor().is_registrar
|
2021-02-24 19:59:48 +00:00
|
|
|
|
|
|
|
|
for i in range(10):
|
|
|
|
|
nums.append(i)
|
|
|
|
|
await trio.sleep(0.1)
|
2018-06-12 19:23:58 +00:00
|
|
|
|
|
|
|
|
start = time.time()
|
2021-02-24 19:59:48 +00:00
|
|
|
trio.run(print_loop)
|
2018-06-19 15:49:25 +00:00
|
|
|
|
2018-06-12 19:23:58 +00:00
|
|
|
# ensure the sleeps were actually awaited
|
|
|
|
|
assert time.time() - start >= 1
|
2018-06-19 15:49:25 +00:00
|
|
|
assert nums == list(range(10))
|