Merge pull request #39 from tgoodlet/self_register
Verify arbiter self registration worksloglevel_to_tractor_tests
commit
8b7bf4fc07
|
@ -31,6 +31,26 @@ def test_no_main():
|
|||
tractor.run(None)
|
||||
|
||||
|
||||
@tractor_test
|
||||
async def test_self_is_registered():
|
||||
"Verify waiting on the arbiter to register itself using the standard api."
|
||||
actor = tractor.current_actor()
|
||||
assert actor.is_arbiter
|
||||
async with tractor.wait_for_actor('arbiter') as portal:
|
||||
assert portal.channel.uid[0] == 'arbiter'
|
||||
|
||||
|
||||
@tractor_test
|
||||
async def test_self_is_registered_localportal(arb_addr):
|
||||
"Verify waiting on the arbiter to register itself using a local portal."
|
||||
actor = tractor.current_actor()
|
||||
assert actor.is_arbiter
|
||||
async with tractor.get_arbiter(*arb_addr) as portal:
|
||||
assert isinstance(portal, tractor._portal.LocalPortal)
|
||||
sockaddr = await portal.run('self', 'wait_for_actor', name='arbiter')
|
||||
assert sockaddr[0] == arb_addr
|
||||
|
||||
|
||||
def test_local_actor_async_func(arb_addr):
|
||||
"""Verify a simple async function in-process.
|
||||
"""
|
||||
|
|
|
@ -768,7 +768,7 @@ async def wait_for_actor(
|
|||
) -> typing.AsyncGenerator[Portal, None]:
|
||||
"""Wait on an actor to register with the arbiter.
|
||||
|
||||
A portal to the first actor which registered is be returned.
|
||||
A portal to the first registered actor is returned.
|
||||
"""
|
||||
actor = current_actor()
|
||||
async with get_arbiter(*arbiter_sockaddr or actor._arb_addr) as arb_portal:
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
Portal api
|
||||
"""
|
||||
import importlib
|
||||
import inspect
|
||||
import typing
|
||||
from typing import Tuple, Any, Dict, Optional
|
||||
|
||||
|
@ -216,11 +217,15 @@ class LocalPortal:
|
|||
) -> None:
|
||||
self.actor = actor
|
||||
|
||||
async def run(self, ns: str, func: str, **kwargs) -> Any:
|
||||
async def run(self, ns: str, func_name: str, **kwargs) -> Any:
|
||||
"""Run a requested function locally and return it's result.
|
||||
"""
|
||||
obj = self.actor if ns == 'self' else importlib.import_module(ns)
|
||||
return getattr(obj, func)(**kwargs)
|
||||
func = getattr(obj, func_name)
|
||||
if inspect.iscoroutinefunction(func):
|
||||
return await func(**kwargs)
|
||||
else:
|
||||
return func(**kwargs)
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
|
|
Loading…
Reference in New Issue