Test the `wait_for_actor()` api

wait_for_actor
Tyler Goodlet 2018-08-13 00:06:22 -04:00
parent 3f0c644768
commit ea60a3dff9
1 changed files with 11 additions and 4 deletions

View File

@ -1,6 +1,7 @@
""" """
Actor "discovery" testing Actor "discovery" testing
""" """
import pytest
import tractor import tractor
import trio import trio
@ -49,8 +50,15 @@ async def say_hello(other_actor):
return await portal.run(__name__, 'hi') return await portal.run(__name__, 'hi')
async def say_hello_use_wait(other_actor):
async with tractor.wait_for_actor(other_actor) as portal:
result = await portal.run(__name__, 'hi')
return result
@tractor_test @tractor_test
async def test_trynamic_trio(): @pytest.mark.parametrize('func', [say_hello, say_hello_use_wait])
async def test_trynamic_trio(func):
"""Main tractor entry point, the "master" process (for now """Main tractor entry point, the "master" process (for now
acts as the "director"). acts as the "director").
""" """
@ -59,15 +67,14 @@ async def test_trynamic_trio():
donny = await n.run_in_actor( donny = await n.run_in_actor(
'donny', 'donny',
say_hello, func,
other_actor='gretchen', other_actor='gretchen',
) )
gretchen = await n.run_in_actor( gretchen = await n.run_in_actor(
'gretchen', 'gretchen',
say_hello, func,
other_actor='donny', other_actor='donny',
) )
print(await gretchen.result()) print(await gretchen.result())
print(await donny.result()) print(await donny.result())
await donny.cancel_actor()
print("CUTTTT CUUTT CUT!!?! Donny!! You're supposed to say...") print("CUTTTT CUUTT CUT!!?! Donny!! You're supposed to say...")