Skip to content

Commit

Permalink
payload compressed to well to end up with two chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco committed Nov 12, 2024
1 parent fa63e53 commit 285427f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions tests/test_http_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,21 @@ async def test_write_large_payload_deflate_compression_chunked_data_in_eof(
msg = http.StreamWriter(protocol, loop)
msg.enable_compression("deflate")
msg.enable_chunking()

await msg.write(b"data" * 4096)
await msg.write_eof(b"data" * 4096)
# This payload compresses poorly to ~256KiB.
payload = (
bytes(range(0, 256))
+ bytes(range(255, 0, -1))
+ bytes(range(0, 128))
+ bytes(range(255, 0, -1))
) * 512
await msg.write_eof(payload)

chunks = [c[1][0][1] for c in list(transport.writelines.mock_calls)] # type: ignore[attr-defined]
assert all(chunks)
content = b"".join(chunks)
assert zlib.decompress(content) == b"data" * 8192
assert zlib.decompress(content) == (b"data" * 4096) + payload


async def test_write_payload_deflate_compression_chunked_connection_lost(
Expand Down

0 comments on commit 285427f

Please sign in to comment.