import asyncio from lyra_worker.adapters._streamrip import _run def test_run_reuses_one_persistent_loop_across_calls(): # The event-loop fix: unlike asyncio.run (which creates AND closes a fresh loop per call), # _run runs every streamrip coroutine on ONE persistent loop — so streamrip's loop-bound # global Semaphore stays valid across downloads instead of orphaning on a closed loop. async def current_loop(): return asyncio.get_running_loop() loop_a = _run(current_loop()) loop_b = _run(current_loop()) assert loop_a is loop_b # same loop reused, not a fresh one each call assert not loop_a.is_closed() # still open (asyncio.run would have closed it)