@@ -127,24 +127,25 @@ async def test_async_telemetry_stream_cancellation_survives_direct_routing(
127127) -> None :
128128 monkeypatch .setenv ("KERNEL_BROWSER_ROUTING_SUBRESOURCES" , "telemetry/stream" )
129129 read_started = asyncio .Event ()
130- read_stopped = asyncio .Event ()
130+ transport_cancelled = asyncio .Event ()
131+ chunks : asyncio .Queue [bytes ] = asyncio .Queue ()
131132
132133 class BlockingSSEStream (httpx .AsyncByteStream ):
133134 @override
134135 async def __aiter__ (self ) -> AsyncIterator [bytes ]:
135136 read_started .set ()
136137 try :
137- await asyncio .Event ().wait ()
138- finally :
139- read_stopped .set ()
140- yield b""
138+ while True :
139+ yield await chunks .get ()
140+ except asyncio .CancelledError :
141+ transport_cancelled .set ()
142+ raise
141143
142144 @override
143145 async def aclose (self ) -> None :
144- read_stopped . set ()
146+ pass
145147
146- async def handle_request (request : httpx .Request ) -> httpx .Response :
147- assert request .url .path == "/browser/kernel/telemetry/stream"
148+ async def handle_request (_request : httpx .Request ) -> httpx .Response :
148149 return httpx .Response (
149150 200 ,
150151 headers = {"content-type" : "text/event-stream" },
@@ -168,7 +169,7 @@ async def handle_request(request: httpx.Request) -> httpx.Response:
168169 consumer .cancel ()
169170 with pytest .raises (asyncio .CancelledError ):
170171 await asyncio .wait_for (consumer , timeout = 1 )
171- await asyncio .wait_for (read_stopped .wait (), timeout = 1 )
172+ await asyncio .wait_for (transport_cancelled .wait (), timeout = 1 )
172173
173174
174175@respx .mock
0 commit comments