Skip to content

Commit

Permalink
handle CLOSE packet in the client (Fixes #100)
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed May 26, 2019
1 parent 36a1598 commit 612815f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions engineio/asyncio_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ async def _receive_packet(self, pkt):
await self._trigger_event('message', pkt.data, run_async=True)
elif pkt.packet_type == packet.PONG:
self.pong_received = True
elif pkt.packet_type == packet.CLOSE:
await self.disconnect(abort=True)
elif pkt.packet_type == packet.NOOP:
pass
else:
Expand Down
2 changes: 2 additions & 0 deletions engineio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,8 @@ def _receive_packet(self, pkt):
self._trigger_event('message', pkt.data, run_async=True)
elif pkt.packet_type == packet.PONG:
self.pong_received = True
elif pkt.packet_type == packet.CLOSE:
self.disconnect(abort=True)
elif pkt.packet_type == packet.NOOP:
pass
else:
Expand Down
6 changes: 6 additions & 0 deletions tests/asyncio/test_asyncio_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,12 @@ def test_receive_message_packet(self):
c._trigger_event.mock.assert_called_once_with(
'message', {'foo': 'bar'}, run_async=True)

def test_receive_close_packet(self):
c = asyncio_client.AsyncClient()
c.disconnect = AsyncMock()
_run(c._receive_packet(packet.Packet(packet.CLOSE)))
c.disconnect.mock.assert_called_once_with(abort=True)

def test_send_packet_disconnected(self):
c = asyncio_client.AsyncClient()
c.queue = c.create_queue()
Expand Down
6 changes: 6 additions & 0 deletions tests/common/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,12 @@ def test_receive_message_packet(self):
c._trigger_event.assert_called_once_with('message', {'foo': 'bar'},
run_async=True)

def test_receive_close_packet(self):
c = client.Client()
c.disconnect = mock.MagicMock()
c._receive_packet(packet.Packet(packet.CLOSE))
c.disconnect.assert_called_once_with(abort=True)

def test_send_packet_disconnected(self):
c = client.Client()
c.queue = c.create_queue()
Expand Down

0 comments on commit 612815f

Please sign in to comment.