Skip to content

Commit f55503d

Browse files
Fix flaky coverage (aio-libs#12352)
1 parent 7eb0577 commit f55503d

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/test_web_functional.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,6 +1193,34 @@ async def handler(request: web.Request) -> web.StreamResponse:
11931193
resp.release()
11941194

11951195

1196+
async def test_stream_response_empty_write_between_chunks(
1197+
aiohttp_client: AiohttpClient,
1198+
) -> None:
1199+
"""Test that empty writes between real chunks are harmless.
1200+
1201+
Simulates a streaming handler that writes empty bytes between data,
1202+
as can happen when piping from a source that produces empty reads.
1203+
"""
1204+
1205+
async def handler(request: web.Request) -> web.StreamResponse:
1206+
resp = web.StreamResponse()
1207+
resp.enable_chunked_encoding()
1208+
await resp.prepare(request)
1209+
await resp.write(b"hello")
1210+
await resp.write(b"")
1211+
await resp.write(b"world")
1212+
return resp
1213+
1214+
app = web.Application()
1215+
app.router.add_get("/", handler)
1216+
client = await aiohttp_client(app)
1217+
1218+
resp = await client.get("/")
1219+
assert resp.status == 200
1220+
data = await resp.read()
1221+
assert data == b"helloworld"
1222+
1223+
11961224
async def test_start_without_routes(aiohttp_client: AiohttpClient) -> None:
11971225
app = web.Application()
11981226
client = await aiohttp_client(app)

0 commit comments

Comments
 (0)