diff --git a/socketio/asyncio_server.py b/socketio/asyncio_server.py index b5ee4af..a4c404d 100644 --- a/socketio/asyncio_server.py +++ b/socketio/asyncio_server.py @@ -327,10 +327,10 @@ class AsyncServer(server.Server): """ namespace = namespace or '/' if ignore_queue: - do_it = self.manager.is_connected(sid, namespace) + delete_it = self.manager.is_connected(sid, namespace) else: - do_it = await self.manager.can_disconnect(sid, namespace) - if do_it: + delete_it = await self.manager.can_disconnect(sid, namespace) + if delete_it: self.logger.info('Disconnecting %s [%s]', sid, namespace) self.manager.pre_disconnect(sid, namespace=namespace) await self._send_packet(sid, packet.Packet(packet.DISCONNECT, diff --git a/socketio/server.py b/socketio/server.py index a784fc4..61433e4 100644 --- a/socketio/server.py +++ b/socketio/server.py @@ -518,10 +518,10 @@ class Server(object): """ namespace = namespace or '/' if ignore_queue: - do_it = self.manager.is_connected(sid, namespace) + delete_it = self.manager.is_connected(sid, namespace) else: - do_it = self.manager.can_disconnect(sid, namespace) - if do_it: + delete_it = self.manager.can_disconnect(sid, namespace) + if delete_it: self.logger.info('Disconnecting %s [%s]', sid, namespace) self.manager.pre_disconnect(sid, namespace=namespace) self._send_packet(sid, packet.Packet(packet.DISCONNECT, diff --git a/tests/asyncio/test_asyncio_server.py b/tests/asyncio/test_asyncio_server.py index 1ed42e8..5efe705 100644 --- a/tests/asyncio/test_asyncio_server.py +++ b/tests/asyncio/test_asyncio_server.py @@ -625,6 +625,15 @@ class TestAsyncServer(unittest.TestCase): s.eio.send.mock.assert_any_call('123', '1', binary=False) s.eio.disconnect.mock.assert_called_once_with('123') + def test_disconnect_ignore_queue(self, eio): + eio.return_value.send = AsyncMock() + eio.return_value.disconnect = AsyncMock() + s = asyncio_server.AsyncServer() + _run(s._handle_eio_connect('123', 'environ')) + _run(s.disconnect('123', ignore_queue=True)) + s.eio.send.mock.assert_any_call('123', '1', binary=False) + s.eio.disconnect.mock.assert_called_once_with('123') + def test_disconnect_namespace(self, eio): eio.return_value.send = AsyncMock() eio.return_value.disconnect = AsyncMock() diff --git a/tests/common/test_server.py b/tests/common/test_server.py index 38fbb08..70dbf57 100644 --- a/tests/common/test_server.py +++ b/tests/common/test_server.py @@ -553,6 +553,12 @@ class TestServer(unittest.TestCase): s.disconnect('123') s.eio.send.assert_any_call('123', '1', binary=False) + def test_disconnect_ignore_queue(self, eio): + s = server.Server() + s._handle_eio_connect('123', 'environ') + s.disconnect('123', ignore_queue=True) + s.eio.send.assert_any_call('123', '1', binary=False) + def test_disconnect_namespace(self, eio): s = server.Server() s._handle_eio_connect('123', 'environ')