Skip to content

Commit c4b3d2b

Browse files
add a unit test
1 parent f4d0b20 commit c4b3d2b

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/websockets/asyncio/messages.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ def prepare_close(self) -> None:
292292

293293
# Resuming the writer to avoid deadlocks
294294
if self.paused:
295+
self.paused = False
295296
self.resume()
296297

297298
def close(self) -> None:

tests/asyncio/test_connection.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,27 @@ async def test_close_preserves_queued_messages(self):
806806
self.assertEqual(str(exc), "sent 1000 (OK); then received 1000 (OK)")
807807
self.assertIsNone(exc.__cause__)
808808

809+
async def test_close_preserves_queued_messages_gt_max_queue(self):
810+
"""
811+
close preserves messages buffered in the assembler, even if they
812+
exceed the default buffer size.
813+
"""
814+
815+
for _ in range(100):
816+
await self.remote_connection.send("😀")
817+
818+
await self.connection.close()
819+
820+
for _ in range(100):
821+
self.assertEqual(await self.connection.recv(), "😀")
822+
823+
with self.assertRaises(ConnectionClosedOK) as raised:
824+
await self.connection.recv()
825+
826+
exc = raised.exception
827+
self.assertEqual(str(exc), "sent 1000 (OK); then received 1000 (OK)")
828+
self.assertIsNone(exc.__cause__)
829+
809830
async def test_close_idempotency(self):
810831
"""close does nothing if the connection is already closed."""
811832
await self.connection.close()

0 commit comments

Comments
 (0)