Skip to content

Commit

Permalink
test for non-executor path
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco committed Nov 22, 2023
1 parent e49bc6a commit 557812f
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions tests/test_websocket_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,41 @@ async def test_send_compress_text_per_message(protocol: Any, transport: Any) ->


@mock.patch("aiohttp.http_websocket.WEBSOCKET_MAX_SYNC_CHUNK_SIZE", 16)
async def test_concurrent_messages(protocol: Any, transport: Any) -> None:
"""Ensure messages are compressed correctly when there are multiple concurrent writers."""
async def test_concurrent_messages_with_executor(protocol: Any, transport: Any) -> None:
"""Ensure messages are compressed correctly when there are multiple concurrent writers.
This test generates messages large enough that they will
be compressed in the executor.
"""
writer = WebSocketWriter(protocol, transport, compress=15)
queue: DataQueue[WSMessage] = DataQueue(asyncio.get_running_loop())
reader = WebSocketReader(queue, 50000)
writers = []
payloads = []
msg_length = 16 + 1
for count in range(1, 64 + 1):
payload = bytes((count,)) * msg_length
payloads.append(payload)
writers.append(writer.send(payload, binary=True))
await asyncio.gather(*writers)
for call in writer.transport.write.call_args_list:
call_bytes = call[0][0]
result, _ = reader.feed_data(call_bytes)
assert result is False
msg = await queue.read()
bytes_data: bytes = msg.data
assert len(bytes_data) == msg_length
assert bytes_data == bytes_data[0:1] * msg_length


async def test_concurrent_messages_without_executor(
protocol: Any, transport: Any
) -> None:
"""Ensure messages are compressed correctly when there are multiple concurrent writers.
This test generates messages that are small enough that
they will not be compressed in the executor.
"""
writer = WebSocketWriter(protocol, transport, compress=15)
queue: DataQueue[WSMessage] = DataQueue(asyncio.get_running_loop())
reader = WebSocketReader(queue, 50000)
Expand Down

0 comments on commit 557812f

Please sign in to comment.