Skip to content

Commit 45d880c

Browse files
correct handling of disconnects
fixes #227
1 parent a6282ad commit 45d880c

File tree

4 files changed

+7
-0
lines changed

4 files changed

+7
-0
lines changed

socketio/asyncio_client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ async def disconnect(self):
197197
await self._trigger_event('disconnect', namespace='/')
198198
await self._send_packet(packet.Packet(
199199
packet.DISCONNECT, namespace='/'))
200+
await self.eio.disconnect(abort=True)
200201

201202
def start_background_task(self, target, *args, **kwargs):
202203
"""Start a background task using the appropriate async model.

socketio/client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ def disconnect(self):
293293
self._trigger_event('disconnect', namespace='/')
294294
self._send_packet(packet.Packet(
295295
packet.DISCONNECT, namespace='/'))
296+
self.eio.disconnect(abort=True)
296297

297298
def transport(self):
298299
"""Return the name of the transport used by the client.

tests/test_asyncio_client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,13 +262,16 @@ def test_disconnect(self):
262262
c = asyncio_client.AsyncClient()
263263
c._trigger_event = AsyncMock()
264264
c._send_packet = AsyncMock()
265+
c.eio = mock.MagicMock()
266+
c.eio.disconnect = AsyncMock()
265267
_run(c.disconnect())
266268
c._trigger_event.mock.assert_called_once_with(
267269
'disconnect', namespace='/')
268270
self.assertEqual(c._send_packet.mock.call_count, 1)
269271
expected_packet = packet.Packet(packet.DISCONNECT, namespace='/')
270272
self.assertEqual(c._send_packet.mock.call_args_list[0][0][0].encode(),
271273
expected_packet.encode())
274+
c.eio.disconnect.mock.assert_called_once_with(abort=True)
272275

273276
def test_disconnect_namespaces(self):
274277
c = asyncio_client.AsyncClient()

tests/test_client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,12 +336,14 @@ def test_disconnect(self):
336336
c = client.Client()
337337
c._trigger_event = mock.MagicMock()
338338
c._send_packet = mock.MagicMock()
339+
c.eio = mock.MagicMock()
339340
c.disconnect()
340341
c._trigger_event.assert_called_once_with('disconnect', namespace='/')
341342
self.assertEqual(c._send_packet.call_count, 1)
342343
expected_packet = packet.Packet(packet.DISCONNECT, namespace='/')
343344
self.assertEqual(c._send_packet.call_args_list[0][0][0].encode(),
344345
expected_packet.encode())
346+
c.eio.disconnect.assert_called_once_with(abort=True)
345347

346348
def test_disconnect_namespaces(self):
347349
c = client.Client()

0 commit comments

Comments
 (0)