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,23 +11,32 @@ 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)
async with tractor.open_root_actor(
arbiter_addr=arb_addr,
):
actor = tractor.current_actor() actor = tractor.current_actor()
assert actor.is_arbiter == is_arbiter assert actor.is_arbiter == is_arbiter
data == data_to_pass_down data = data_to_pass_down
if actor.is_arbiter: if actor.is_arbiter:
async with tractor.open_nursery() as nursery:
async with tractor.open_nursery(
) as nursery:
# forks here # forks here
portal = await nursery.run_in_actor( portal = await nursery.run_in_actor(
spawn, spawn,
is_arbiter=False, is_arbiter=False,
name='sub-actor', name='sub-actor',
data=data, data=data,
rpc_module_paths=namespaces, arb_addr=arb_addr,
enable_modules=namespaces,
) )
assert len(nursery._children) == 1 assert len(nursery._children) == 1
@ -42,11 +50,11 @@ async def spawn(is_arbiter, data):
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