From 07831d4c0c8a7876e550552dba459d2114cadda2 Mon Sep 17 00:00:00 2001 From: Daniel Han Date: Sun, 24 May 2026 19:54:08 +0000 Subject: [PATCH] Shut down asyncgens in routing tests to silence cleanup warnings (PR #5711) Round 18 reviewers (and earlier) noted CI noise from the routing test helper: `_drive(coro)` ran a fresh event loop but never closed it or called `shutdown_asyncgens`, so the MockTransport-backed httpx async generators in the providers were finalised by GC in a later task and emitted "Response.aiter_text.aclose was never awaited" / "Task was destroyed but it is pending" warnings. Explicitly close the loop after `run_until_complete`, running `shutdown_asyncgens` first so the iterators finalise in this task. Tests still pass and the warnings are gone. --- .../backend/tests/test_sampling_params_routing.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/studio/backend/tests/test_sampling_params_routing.py b/studio/backend/tests/test_sampling_params_routing.py index 0c6220bc8d..1a0b3fed60 100644 --- a/studio/backend/tests/test_sampling_params_routing.py +++ b/studio/backend/tests/test_sampling_params_routing.py @@ -31,7 +31,18 @@ from core.inference.external_provider import ExternalProviderClient def _drive(coro): - return asyncio.new_event_loop().run_until_complete(coro) + # Explicit loop lifecycle + asyncgen shutdown so the httpx / + # MockTransport-backed async generators in the providers are + # finalised in this task instead of being collected later (which + # triggers the "aiter_text aclose was never awaited" warning the + # reviewer round noticed). + loop = asyncio.new_event_loop() + try: + result = loop.run_until_complete(coro) + loop.run_until_complete(loop.shutdown_asyncgens()) + return result + finally: + loop.close() def _install_mock(monkeypatch, *, sse_payload: bytes | None = None) -> dict: