Browse Source

correct handling of disconnects

fixes #227
pull/229/head
Miguel Grinberg 6 years ago
parent
commit
45d880cf90
  1. 1
      socketio/asyncio_client.py
  2. 1
      socketio/client.py
  3. 3
      tests/test_asyncio_client.py
  4. 2
      tests/test_client.py

1
socketio/asyncio_client.py

@ -197,6 +197,7 @@ class AsyncClient(client.Client):
await self._trigger_event('disconnect', namespace='/')
await self._send_packet(packet.Packet(
packet.DISCONNECT, namespace='/'))
await self.eio.disconnect(abort=True)
def start_background_task(self, target, *args, **kwargs):
"""Start a background task using the appropriate async model.

1
socketio/client.py

@ -293,6 +293,7 @@ class Client(object):
self._trigger_event('disconnect', namespace='/')
self._send_packet(packet.Packet(
packet.DISCONNECT, namespace='/'))
self.eio.disconnect(abort=True)
def transport(self):
"""Return the name of the transport used by the client.

3
tests/test_asyncio_client.py

@ -262,6 +262,8 @@ class TestAsyncClient(unittest.TestCase):
c = asyncio_client.AsyncClient()
c._trigger_event = AsyncMock()
c._send_packet = AsyncMock()
c.eio = mock.MagicMock()
c.eio.disconnect = AsyncMock()
_run(c.disconnect())
c._trigger_event.mock.assert_called_once_with(
'disconnect', namespace='/')
@ -269,6 +271,7 @@ class TestAsyncClient(unittest.TestCase):
expected_packet = packet.Packet(packet.DISCONNECT, namespace='/')
self.assertEqual(c._send_packet.mock.call_args_list[0][0][0].encode(),
expected_packet.encode())
c.eio.disconnect.mock.assert_called_once_with(abort=True)
def test_disconnect_namespaces(self):
c = asyncio_client.AsyncClient()

2
tests/test_client.py

@ -336,12 +336,14 @@ class TestClient(unittest.TestCase):
c = client.Client()
c._trigger_event = mock.MagicMock()
c._send_packet = mock.MagicMock()
c.eio = mock.MagicMock()
c.disconnect()
c._trigger_event.assert_called_once_with('disconnect', namespace='/')
self.assertEqual(c._send_packet.call_count, 1)
expected_packet = packet.Packet(packet.DISCONNECT, namespace='/')
self.assertEqual(c._send_packet.call_args_list[0][0][0].encode(),
expected_packet.encode())
c.eio.disconnect.assert_called_once_with(abort=True)
def test_disconnect_namespaces(self):
c = client.Client()

Loading…
Cancel
Save