Skip to content

Commit

Permalink
Test that from_thread works when the calling thread is running Trio
Browse files Browse the repository at this point in the history
  • Loading branch information
gschaffner committed Jan 24, 2023
1 parent 4286063 commit 0b84a5f
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion trio/tests/test_threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 = []
Expand Down

0 comments on commit 0b84a5f

Please sign in to comment.