forked from goodboy/tractor
1
0
Fork 0

Drop run and rpc_module_paths from spawning tests

drop_run
Tyler Goodlet 2021-02-24 18:16:10 -05:00
parent 1eedd463cb
commit 3bddf9a94b
1 changed files with 45 additions and 36 deletions

View File

@ -1,7 +1,6 @@
""" """
Spawning basics Spawning basics
""" """
from functools import partial
import pytest import pytest
import trio import trio
@ -12,41 +11,50 @@ from conftest import tractor_test
data_to_pass_down = {'doggy': 10, 'kitty': 4} data_to_pass_down = {'doggy': 10, 'kitty': 4}
async def spawn(is_arbiter, data): async def spawn(is_arbiter, data, arb_addr):
namespaces = [__name__] namespaces = [__name__]
await trio.sleep(0.1) await trio.sleep(0.1)
actor = tractor.current_actor()
assert actor.is_arbiter == is_arbiter
data == data_to_pass_down
if actor.is_arbiter: async with tractor.open_root_actor(
async with tractor.open_nursery() as nursery: arbiter_addr=arb_addr,
# forks here ):
portal = await nursery.run_in_actor(
spawn,
is_arbiter=False,
name='sub-actor',
data=data,
rpc_module_paths=namespaces,
)
assert len(nursery._children) == 1 actor = tractor.current_actor()
assert portal.channel.uid in tractor.current_actor()._peers assert actor.is_arbiter == is_arbiter
# be sure we can still get the result data = data_to_pass_down
result = await portal.result()
assert result == 10 if actor.is_arbiter:
return result
else: async with tractor.open_nursery(
return 10 ) as nursery:
# forks here
portal = await nursery.run_in_actor(
spawn,
is_arbiter=False,
name='sub-actor',
data=data,
arb_addr=arb_addr,
enable_modules=namespaces,
)
assert len(nursery._children) == 1
assert portal.channel.uid in tractor.current_actor()._peers
# be sure we can still get the result
result = await portal.result()
assert result == 10
return result
else:
return 10
def test_local_arbiter_subactor_global_state(arb_addr): def test_local_arbiter_subactor_global_state(arb_addr):
result = tractor.run( result = trio.run(
partial(spawn, data=data_to_pass_down), spawn,
True, True,
name='arbiter', data_to_pass_down,
arbiter_addr=arb_addr, arb_addr,
) )
assert result == 10 assert result == 10
@ -67,7 +75,7 @@ async def test_movie_theatre_convo(start_method):
portal = await n.start_actor( portal = await n.start_actor(
'frank', 'frank',
# enable the actor to run funcs from this current module # enable the actor to run funcs from this current module
rpc_module_paths=[__name__], enable_modules=[__name__],
) )
print(await portal.run(movie_theatre_question)) print(await portal.run(movie_theatre_question))
@ -121,19 +129,20 @@ def test_loglevel_propagated_to_subactor(
level = 'critical' level = 'critical'
async def main(): async def main():
async with tractor.open_nursery() as tn: async with tractor.open_nursery(
name='arbiter',
loglevel=level,
start_method=start_method,
arbiter_addr=arb_addr,
) as tn:
await tn.run_in_actor( await tn.run_in_actor(
check_loglevel, check_loglevel,
level=level, level=level,
) )
tractor.run( trio.run(main)
main,
name='arbiter',
loglevel=level,
start_method=start_method,
arbiter_addr=arb_addr,
)
# ensure subactor spits log message on stderr # ensure subactor spits log message on stderr
captured = capfd.readouterr() captured = capfd.readouterr()
assert 'yoyoyo' in captured.err assert 'yoyoyo' in captured.err