From 0b84a5fdbe21345d396ed7983a760ddfb1c832d0 Mon Sep 17 00:00:00 2001 From: Ganden Schaffner Date: Tue, 24 Jan 2023 00:00:00 -0800 Subject: [PATCH] Test that from_thread works when the calling thread is running Trio --- trio/tests/test_threads.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/trio/tests/test_threads.py b/trio/tests/test_threads.py index ce852d4612..4e15ee9805 100644 --- a/trio/tests/test_threads.py +++ b/trio/tests/test_threads.py @@ -818,7 +818,7 @@ def test_run_fn_as_system_task_catched_badly_typed_token(): from_thread_run_sync(_core.current_time, trio_token="Not TrioTokentype") -async def test_from_thread_inside_trio_thread(): +async def test_from_thread_inside_same_trio_thread(): def not_called(): # pragma: no cover assert False @@ -827,6 +827,15 @@ def not_called(): # pragma: no cover from_thread_run_sync(not_called, trio_token=trio_token) +async def test_from_thread_inside_different_trio_thread(): + target_token = current_trio_token() + + async def thread_fn(): + return from_thread_run_sync(current_trio_token, trio_token=target_token) + + assert target_token == await to_thread_run_sync(_core.run, thread_fn) + + @pytest.mark.skipif(buggy_pypy_asyncgens, reason="pypy 7.2.0 is buggy") def test_from_thread_run_during_shutdown(): save = []