Skip to content

Commit ec3f0c0

Browse files
committed
adjust shutdown test
1 parent 1572905 commit ec3f0c0

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

tests/utils/test_aio.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def test_shutdown_loop() -> None:
6464
"""Test shutting down an event loop."""
6565
loop = None
6666
loop_thread_ready = threading.Event()
67+
runcoro_thread_ready = threading.Event()
6768

6869
def _run_loop() -> None:
6970
nonlocal loop
@@ -76,10 +77,23 @@ def _run_loop() -> None:
7677
loop_thread.start()
7778
loop_thread_ready.wait()
7879

80+
async def _still_running():
81+
await asyncio.sleep(5)
82+
83+
def _run_coro() -> None:
84+
runcoro_thread_ready.set()
85+
asyncio.run_coroutine_threadsafe(_still_running(), loop).result(1)
86+
87+
runcoro_thread = threading.Thread(target=_run_coro, daemon=True)
88+
runcoro_thread.start()
89+
runcoro_thread_ready.wait()
90+
91+
time.sleep(0.1)
7992
aioutils.shutdown_loop(loop)
8093
for _ in range(5):
8194
if not loop.is_running():
8295
break
8396
time.sleep(0.05)
8497

8598
assert loop.is_running() is False
99+
runcoro_thread.join()

0 commit comments

Comments
 (0)