Skip to content

Commit 3461271

Browse files
committed
fix frame compression tests in test_webssocket_writer
1 parent 4620c4e commit 3461271

1 file changed

Lines changed: 21 additions & 4 deletions

File tree

tests/test_websocket_writer.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from aiohttp import WSMsgType
99
from aiohttp._websocket.reader import WebSocketDataQueue
1010
from aiohttp.base_protocol import BaseProtocol
11+
from aiohttp.compression_utils import ZLibBackend
1112
from aiohttp.http import WebSocketReader, WebSocketWriter
1213

1314

@@ -86,24 +87,40 @@ async def test_send_text_masked(
8687
writer.transport.write.assert_called_with(b"\x81\x84\rg\xb3fy\x02\xcb\x12") # type: ignore[attr-defined]
8788

8889

90+
@pytest.mark.usefixtures("parametrize_zlib_backend")
8991
async def test_send_compress_text(
9092
protocol: BaseProtocol, transport: asyncio.Transport
9193
) -> None:
94+
compress_obj = ZLibBackend.compressobj(level=ZLibBackend.Z_BEST_SPEED, wbits=-15)
9295
writer = WebSocketWriter(protocol, transport, compress=15)
96+
97+
msg = (
98+
compress_obj.compress(b"text") + compress_obj.flush(ZLibBackend.Z_SYNC_FLUSH)
99+
).removesuffix(b"\x00\x00\xff\xff")
93100
await writer.send_frame(b"text", WSMsgType.TEXT)
94-
writer.transport.write.assert_called_with(b"\xc1\x06*I\xad(\x01\x00") # type: ignore[attr-defined]
101+
writer.transport.write.assert_called_with(b"\xc1" + len(msg).to_bytes(1) + msg) # type: ignore[attr-defined]
102+
103+
msg = (
104+
compress_obj.compress(b"text") + compress_obj.flush(ZLibBackend.Z_SYNC_FLUSH)
105+
).removesuffix(b"\x00\x00\xff\xff")
95106
await writer.send_frame(b"text", WSMsgType.TEXT)
96-
writer.transport.write.assert_called_with(b"\xc1\x05*\x01b\x00\x00") # type: ignore[attr-defined]
107+
writer.transport.write.assert_called_with(b"\xc1" + len(msg).to_bytes(1) + msg) # type: ignore[attr-defined]
97108

98109

110+
@pytest.mark.usefixtures("parametrize_zlib_backend")
99111
async def test_send_compress_text_notakeover(
100112
protocol: BaseProtocol, transport: asyncio.Transport
101113
) -> None:
114+
compress_obj = ZLibBackend.compressobj(level=ZLibBackend.Z_BEST_SPEED, wbits=-15)
102115
writer = WebSocketWriter(protocol, transport, compress=15, notakeover=True)
116+
117+
msg = (
118+
compress_obj.compress(b"text") + compress_obj.flush(ZLibBackend.Z_FULL_FLUSH)
119+
).removesuffix(b"\x00\x00\xff\xff")
103120
await writer.send_frame(b"text", WSMsgType.TEXT)
104-
writer.transport.write.assert_called_with(b"\xc1\x06*I\xad(\x01\x00") # type: ignore[attr-defined]
121+
writer.transport.write.assert_called_with(b"\xc1" + len(msg).to_bytes(1) + msg) # type: ignore[attr-defined]
105122
await writer.send_frame(b"text", WSMsgType.TEXT)
106-
writer.transport.write.assert_called_with(b"\xc1\x06*I\xad(\x01\x00") # type: ignore[attr-defined]
123+
writer.transport.write.assert_called_with(b"\xc1" + len(msg).to_bytes(1) + msg) # type: ignore[attr-defined]
107124

108125

109126
async def test_send_compress_text_per_message(

0 commit comments

Comments
 (0)