Skip to content

Commit

Permalink
CR
Browse files Browse the repository at this point in the history
  • Loading branch information
oremanj committed Apr 24, 2024
1 parent ad75cf7 commit cf7a25f
Showing 1 changed file with 26 additions and 21 deletions.
47 changes: 26 additions & 21 deletions tests/test_trio_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,31 +243,36 @@ async def iterate_one(label, extra=""):

sys.unraisablehook, prev_hook = sys.__unraisablehook__, sys.unraisablehook
try:
before_hooks = sys.get_asyncgen_hooks()

start_time = trio.current_time()
with trio.move_on_after(loop_timeout) as scope:
if loop_timeout == 0:
scope.cancel()
async with trio_asyncio.open_loop() as loop:
async with trio_asyncio.open_loop() as loop2:
async with trio.open_nursery() as nursery:
# Make sure the iterate_one aio tasks don't get
# cancelled before they start:
nursery.cancel_scope.shield = True
try:
nursery.start_soon(iterate_one, "trio")
nursery.start_soon(
loop.run_aio_coroutine, iterate_one("asyncio")
)
nursery.start_soon(
loop2.run_aio_coroutine, iterate_one("asyncio", "2")
)
await loop.synchronize()
await loop2.synchronize()
finally:
nursery.cancel_scope.shield = False
if not alive_on_exit and sys.implementation.name == "pypy":
for _ in range(5):
gc.collect()
async with trio_asyncio.open_loop() as loop, trio_asyncio.open_loop() as loop2:
assert sys.get_asyncgen_hooks() != before_hooks
async with trio.open_nursery() as nursery:
# Make sure the iterate_one aio tasks don't get
# cancelled before they start:
nursery.cancel_scope.shield = True
try:
nursery.start_soon(iterate_one, "trio")
nursery.start_soon(
loop.run_aio_coroutine, iterate_one("asyncio")
)
nursery.start_soon(
loop2.run_aio_coroutine, iterate_one("asyncio", "2")
)
await loop.synchronize()
await loop2.synchronize()
finally:
nursery.cancel_scope.shield = False
if not alive_on_exit and sys.implementation.name == "pypy":
for _ in range(5):
gc.collect()

# Make sure we cleaned up properly once all trio-aio loops were closed
assert sys.get_asyncgen_hooks() == before_hooks

# asyncio agens should be finalized as soon as asyncio loop ends,
# regardless of liveness
Expand Down

0 comments on commit cf7a25f

Please sign in to comment.