Skip to content

Commit

Permalink
add a unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
btschwertfeger committed Nov 28, 2024
1 parent f4d0b20 commit c4b3d2b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/websockets/asyncio/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ def prepare_close(self) -> None:

# Resuming the writer to avoid deadlocks
if self.paused:
self.paused = False
self.resume()

def close(self) -> None:
Expand Down
21 changes: 21 additions & 0 deletions tests/asyncio/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,27 @@ async def test_close_preserves_queued_messages(self):
self.assertEqual(str(exc), "sent 1000 (OK); then received 1000 (OK)")
self.assertIsNone(exc.__cause__)

async def test_close_preserves_queued_messages_gt_max_queue(self):
"""
close preserves messages buffered in the assembler, even if they
exceed the default buffer size.
"""

for _ in range(100):
await self.remote_connection.send("😀")

await self.connection.close()

for _ in range(100):
self.assertEqual(await self.connection.recv(), "😀")

with self.assertRaises(ConnectionClosedOK) as raised:
await self.connection.recv()

exc = raised.exception
self.assertEqual(str(exc), "sent 1000 (OK); then received 1000 (OK)")
self.assertIsNone(exc.__cause__)

async def test_close_idempotency(self):
"""close does nothing if the connection is already closed."""
await self.connection.close()
Expand Down

0 comments on commit c4b3d2b

Please sign in to comment.