From f32ccd76aaeca6eb791d2544d6844f4fd46f8c2c Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Sat, 20 Nov 2021 12:51:29 -0500 Subject: [PATCH] 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... --- tests/test_spawning.py | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/tests/test_spawning.py b/tests/test_spawning.py index b1110fe..ba3f6f9 100644 --- a/tests/test_spawning.py +++ b/tests/test_spawning.py @@ -1,7 +1,7 @@ """ Spawning basics """ -from typing import Dict, Tuple +from typing import Dict, Tuple, Optional import pytest import trio @@ -93,24 +93,38 @@ async def test_movie_theatre_convo(start_method): await portal.cancel_actor() -async def cellar_door(): - return "Dang that's beautiful" +async def cellar_door(return_value: Optional[str]): + return return_value +@pytest.mark.parametrize( + 'return_value', ["Dang that's beautiful", None], + ids=['return_str', 'return_None'], +) @tractor_test -async def test_most_beautiful_word(start_method): - """The main ``tractor`` routine. - """ - async with tractor.open_nursery() as n: +async def test_most_beautiful_word( + start_method, + return_value +): + ''' + The main ``tractor`` routine. - portal = await n.run_in_actor( - cellar_door, - name='some_linguist', - ) + ''' + with trio.fail_after(0.5): + async with tractor.open_nursery() as n: + portal = await n.run_in_actor( + cellar_door, + return_value=return_value, + name='some_linguist', + ) + + print(await portal.result()) # The ``async with`` will unblock here since the 'some_linguist' # 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())