From 7e344dc0dc726db113e6c72df608e1142c3966bb Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Tue, 4 Aug 2026 12:32:20 +0530 Subject: [PATCH] test: exercise the production _loop_ref path in put_threadsafe tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Gate finding (/simplify-code pass): both cross-thread tests passed loop=loop explicitly, but no production caller does — all six (_on_delta, _on_tool_*) rely on the queue resolving its own _loop_ref in __init__. The kwarg made the tests vacuous: a broken _loop_ref still passed them. Dropping the kwarg exercises the real path. Verified by mutation: with self._loop_ref = asyncio.new_event_loop() (wrong loop), both tests now FAIL; they passed before this change. --- tests/gateway/test_sse_agent_cancel.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/gateway/test_sse_agent_cancel.py b/tests/gateway/test_sse_agent_cancel.py index f46d2b574704e..83fabe7c6da98 100644 --- a/tests/gateway/test_sse_agent_cancel.py +++ b/tests/gateway/test_sse_agent_cancel.py @@ -423,7 +423,11 @@ class TestThreadSafeAsyncQueueCrossThreadBoundary: def worker(): time.sleep(0.05) - q.put_threadsafe("from-worker", loop=loop) + # No ``loop=`` kwarg on purpose: production callers + # (_on_delta / _on_tool_*) never pass one, so the queue + # must resolve its own ``_loop_ref``. Passing loop= here + # would make a broken _loop_ref pass this test. + q.put_threadsafe("from-worker") thread = threading.Thread(target=worker, daemon=True) thread.start() @@ -454,7 +458,9 @@ class TestThreadSafeAsyncQueueCrossThreadBoundary: def worker(idx): time.sleep(0.01 + idx * 0.002) - q.put_threadsafe(f"item-{idx}", loop=loop) + # No ``loop=`` kwarg — exercise the production + # ``_loop_ref`` resolution path (see the note above). + q.put_threadsafe(f"item-{idx}") threads = [ threading.Thread(target=worker, args=(i,), daemon=True)