From b2d8ebd981d4acb1ef4c2b40a9f2728d005bcd70 Mon Sep 17 00:00:00 2001 From: rgarcia <72655+rgarcia@users.noreply.github.com> Date: Mon, 10 Aug 2026 19:10:46 +0000 Subject: [PATCH 1/2] Assert stream cancellation reaches transport --- tests/test_browser_routing.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/tests/test_browser_routing.py b/tests/test_browser_routing.py index 9b37908e..cd502fa1 100644 --- a/tests/test_browser_routing.py +++ b/tests/test_browser_routing.py @@ -127,24 +127,25 @@ async def test_async_telemetry_stream_cancellation_survives_direct_routing( ) -> None: monkeypatch.setenv("KERNEL_BROWSER_ROUTING_SUBRESOURCES", "telemetry/stream") read_started = asyncio.Event() - read_stopped = asyncio.Event() + transport_cancelled = asyncio.Event() + chunks: asyncio.Queue[bytes] = asyncio.Queue() class BlockingSSEStream(httpx.AsyncByteStream): @override async def __aiter__(self) -> AsyncIterator[bytes]: read_started.set() try: - await asyncio.Event().wait() - finally: - read_stopped.set() - yield b"" + while True: + yield await chunks.get() + except asyncio.CancelledError: + transport_cancelled.set() + raise @override async def aclose(self) -> None: - read_stopped.set() + pass - async def handle_request(request: httpx.Request) -> httpx.Response: - assert request.url.path == "/browser/kernel/telemetry/stream" + async def handle_request(_request: httpx.Request) -> httpx.Response: return httpx.Response( 200, headers={"content-type": "text/event-stream"}, @@ -168,7 +169,7 @@ async def handle_request(request: httpx.Request) -> httpx.Response: consumer.cancel() with pytest.raises(asyncio.CancelledError): await asyncio.wait_for(consumer, timeout=1) - await asyncio.wait_for(read_stopped.wait(), timeout=1) + await asyncio.wait_for(transport_cancelled.wait(), timeout=1) @respx.mock From d281b8f7bb61c0ab13e9a7afeec69fcc5975f2c0 Mon Sep 17 00:00:00 2001 From: rgarcia <72655+rgarcia@users.noreply.github.com> Date: Mon, 10 Aug 2026 19:31:08 +0000 Subject: [PATCH 2/2] Clarify stream cancellation test scope --- tests/test_browser_routing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_browser_routing.py b/tests/test_browser_routing.py index cd502fa1..dbb8b895 100644 --- a/tests/test_browser_routing.py +++ b/tests/test_browser_routing.py @@ -122,7 +122,7 @@ def test_telemetry_stream_routes_directly_to_vm(monkeypatch: pytest.MonkeyPatch) @pytest.mark.asyncio -async def test_async_telemetry_stream_cancellation_survives_direct_routing( +async def test_async_telemetry_stream_cancellation_reaches_transport( monkeypatch: pytest.MonkeyPatch, ) -> None: monkeypatch.setenv("KERNEL_BROWSER_ROUTING_SUBRESOURCES", "telemetry/stream")