Add `Portal.result()` is None test case

This demonstrates a bug where if the remote `.run_in_actor()` task
returns `None` then multiple calls to `Portal.result()` will hang
forever...
faster_daemon_cancels
Tyler Goodlet 2021-11-20 12:51:29 -05:00
parent b527fdbe1a
commit f32ccd76aa
1 changed files with 25 additions and 11 deletions

View File

@ -1,7 +1,7 @@
""" """
Spawning basics Spawning basics
""" """
from typing import Dict, Tuple from typing import Dict, Tuple, Optional
import pytest import pytest
import trio import trio
@ -93,24 +93,38 @@ async def test_movie_theatre_convo(start_method):
await portal.cancel_actor() await portal.cancel_actor()
async def cellar_door(): async def cellar_door(return_value: Optional[str]):
return "Dang that's beautiful" return return_value
@pytest.mark.parametrize(
'return_value', ["Dang that's beautiful", None],
ids=['return_str', 'return_None'],
)
@tractor_test @tractor_test
async def test_most_beautiful_word(start_method): async def test_most_beautiful_word(
"""The main ``tractor`` routine. start_method,
""" return_value
):
'''
The main ``tractor`` routine.
'''
with trio.fail_after(0.5):
async with tractor.open_nursery() as n: async with tractor.open_nursery() as n:
portal = await n.run_in_actor( portal = await n.run_in_actor(
cellar_door, cellar_door,
return_value=return_value,
name='some_linguist', name='some_linguist',
) )
print(await portal.result())
# The ``async with`` will unblock here since the 'some_linguist' # The ``async with`` will unblock here since the 'some_linguist'
# actor has completed its main task ``cellar_door``. # actor has completed its main task ``cellar_door``.
# this should pull the cached final result already captured during
# the nursery block exit.
print(await portal.result()) print(await portal.result())