diff --git a/src/socketio/async_server.py b/src/socketio/async_server.py index 5f51844..f10fb8a 100644 --- a/src/socketio/async_server.py +++ b/src/socketio/async_server.py @@ -584,7 +584,7 @@ class AsyncServer(base_server.BaseServer): return self.manager.pre_disconnect(sid, namespace=namespace) await self._trigger_event('disconnect', namespace, sid, - reason or self.reason.UNKNOWN) + reason or self.reason.CLIENT_DISCONNECT) await self.manager.disconnect(sid, namespace, ignore_queue=True) async def _handle_event(self, eio_sid, namespace, id, data): diff --git a/src/socketio/server.py b/src/socketio/server.py index 21a6de4..71c702d 100644 --- a/src/socketio/server.py +++ b/src/socketio/server.py @@ -566,7 +566,7 @@ class Server(base_server.BaseServer): return self.manager.pre_disconnect(sid, namespace=namespace) self._trigger_event('disconnect', namespace, sid, - reason or self.reason.UNKNOWN) + reason or self.reason.CLIENT_DISCONNECT) self.manager.disconnect(sid, namespace, ignore_queue=True) def _handle_event(self, eio_sid, namespace, id, data): diff --git a/tests/async/test_namespace.py b/tests/async/test_namespace.py index 656cb47..526d676 100644 --- a/tests/async/test_namespace.py +++ b/tests/async/test_namespace.py @@ -25,10 +25,10 @@ class TestAsyncNamespace: ns = MyNamespace('/foo') ns._set_server(mock.MagicMock()) - _run(ns.trigger_event('disconnect', 'sid', 'foo')) + await ns.trigger_event('disconnect', 'sid', 'foo') assert result['result'] == ('sid', 'foo') - def test_legacy_disconnect_event(self): + async def test_legacy_disconnect_event(self): result = {} class MyNamespace(async_namespace.AsyncNamespace): @@ -37,10 +37,10 @@ class TestAsyncNamespace: ns = MyNamespace('/foo') ns._set_server(mock.MagicMock()) - _run(ns.trigger_event('disconnect', 'sid', 'foo')) + await ns.trigger_event('disconnect', 'sid', 'foo') assert result['result'] == 'sid' - def test_legacy_disconnect_event_async(self): + async def test_legacy_disconnect_event_async(self): result = {} class MyNamespace(async_namespace.AsyncNamespace): @@ -266,7 +266,7 @@ class TestAsyncNamespace: await ns.disconnect('sid', namespace='/bar') ns.server.disconnect.assert_awaited_with('sid', namespace='/bar') - async def test_disconnect_event(self): + async def test_disconnect_event_client(self): result = {} class MyNamespace(async_namespace.AsyncClientNamespace): diff --git a/tests/async/test_server.py b/tests/async/test_server.py index 34b6c38..f60de27 100644 --- a/tests/async/test_server.py +++ b/tests/async/test_server.py @@ -653,7 +653,8 @@ class TestAsyncServer: await s._handle_eio_message('123', '2/bar,["msg","a","b"]') await s._handle_eio_message('123', '2/foo,["my message","a","b","c"]') await s._handle_eio_message('123', '2/bar,["my message","a","b","c"]') - await s._trigger_event('disconnect', '/bar', sid_bar, s.reason.UNKNOWN) + await s._trigger_event('disconnect', '/bar', sid_bar, + s.reason.CLIENT_DISCONNECT) connect_star_handler.assert_called_once_with('/bar', sid_bar) msg_foo_handler.assert_called_once_with(sid_foo, 'a', 'b') msg_star_handler.assert_called_once_with('/bar', sid_bar, 'a', 'b') diff --git a/tests/common/test_namespace.py b/tests/common/test_namespace.py index be6bccb..f1476e4 100644 --- a/tests/common/test_namespace.py +++ b/tests/common/test_namespace.py @@ -252,7 +252,6 @@ class TestNamespace: ns.trigger_event('disconnect', 'foo') assert result['result'] == 'ok' - def test_event_not_found_client(self): result = {} diff --git a/tests/common/test_server.py b/tests/common/test_server.py index 5ba119a..445d5d9 100644 --- a/tests/common/test_server.py +++ b/tests/common/test_server.py @@ -610,7 +610,8 @@ class TestServer: s._handle_eio_message('123', '2/bar,["msg","a","b"]') s._handle_eio_message('123', '2/foo,["my message","a","b","c"]') s._handle_eio_message('123', '2/bar,["my message","a","b","c"]') - s._trigger_event('disconnect', '/bar', sid_bar, s.reason.UNKNOWN) + s._trigger_event('disconnect', '/bar', sid_bar, + s.reason.CLIENT_DISCONNECT) connect_star_handler.assert_called_once_with('/bar', sid_bar) msg_foo_handler.assert_called_once_with(sid_foo, 'a', 'b') msg_star_handler.assert_called_once_with('/bar', sid_bar, 'a', 'b')