Browse Source
Invoke the disconnect handler when the client initiates a disconnection (Fixes #594)
pull/602/head
Miguel Grinberg
4 years ago
No known key found for this signature in database
GPG Key ID: 36848B262DF5F06C
4 changed files with
4 additions and
2 deletions
-
socketio/asyncio_client.py
-
socketio/client.py
-
tests/asyncio/test_asyncio_client.py
-
tests/common/test_client.py
|
|
@ -255,7 +255,6 @@ class AsyncClient(client.Client): |
|
|
|
for n in self.namespaces: |
|
|
|
await self._send_packet(packet.Packet(packet.DISCONNECT, |
|
|
|
namespace=n)) |
|
|
|
self.connected = False |
|
|
|
await self.eio.disconnect(abort=True) |
|
|
|
|
|
|
|
def start_background_task(self, target, *args, **kwargs): |
|
|
|
|
|
@ -408,7 +408,6 @@ class Client(object): |
|
|
|
# later in _handle_eio_disconnect we invoke the disconnect handler |
|
|
|
for n in self.namespaces: |
|
|
|
self._send_packet(packet.Packet(packet.DISCONNECT, namespace=n)) |
|
|
|
self.connected = False |
|
|
|
self.eio.disconnect(abort=True) |
|
|
|
|
|
|
|
def get_sid(self, namespace=None): |
|
|
|
|
|
@ -406,6 +406,7 @@ class TestAsyncClient(unittest.TestCase): |
|
|
|
|
|
|
|
def test_disconnect(self): |
|
|
|
c = asyncio_client.AsyncClient() |
|
|
|
c.connected = True |
|
|
|
c.namespaces = {'/': '1'} |
|
|
|
c._trigger_event = AsyncMock() |
|
|
|
c._send_packet = AsyncMock() |
|
|
@ -413,6 +414,7 @@ class TestAsyncClient(unittest.TestCase): |
|
|
|
c.eio.disconnect = AsyncMock() |
|
|
|
c.eio.state = 'connected' |
|
|
|
_run(c.disconnect()) |
|
|
|
assert c.connected |
|
|
|
assert c._trigger_event.mock.call_count == 0 |
|
|
|
assert c._send_packet.mock.call_count == 1 |
|
|
|
expected_packet = packet.Packet(packet.DISCONNECT, namespace='/') |
|
|
|
|
|
@ -508,12 +508,14 @@ class TestClient(unittest.TestCase): |
|
|
|
|
|
|
|
def test_disconnect(self): |
|
|
|
c = client.Client() |
|
|
|
c.connected = True |
|
|
|
c.namespaces = {'/': '1'} |
|
|
|
c._trigger_event = mock.MagicMock() |
|
|
|
c._send_packet = mock.MagicMock() |
|
|
|
c.eio = mock.MagicMock() |
|
|
|
c.eio.state = 'connected' |
|
|
|
c.disconnect() |
|
|
|
assert c.connected |
|
|
|
assert c._trigger_event.call_count == 0 |
|
|
|
assert c._send_packet.call_count == 1 |
|
|
|
expected_packet = packet.Packet(packet.DISCONNECT, namespace='/') |
|
|
|