Skip to content

Commit

Permalink
Add test for detection in sync callback
Browse files Browse the repository at this point in the history
  • Loading branch information
tapetersen committed Nov 21, 2022
1 parent 07c2df7 commit cd98c11
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions sniffio/_tests/test_sniffio.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,30 @@ async def this_is_asyncio():
current_async_library()


def test_in_call_soon_threadsafe():
import asyncio

asynclib = None
completed = asyncio.Event()

def sync_in_loop():
nonlocal asynclib
try:
asynclib = current_async_library()
finally:
completed.set()

async def async_in_loop():
await completed.wait()

loop = asyncio.new_event_loop()
handle = loop.call_soon_threadsafe(sync_in_loop)
loop.run_until_complete(async_in_loop())
loop.close()

assert asynclib == 'asyncio'


# https://github.com/dabeaz/curio/pull/354
@pytest.mark.skipif(
os.name == "nt" and sys.version_info >= (3, 9),
Expand Down

0 comments on commit cd98c11

Please sign in to comment.