From 14f52f216d49fb52bf223d5d96306465bb61e49c Mon Sep 17 00:00:00 2001 From: Noel Remy Date: Thu, 7 Sep 2023 17:55:12 +0200 Subject: [PATCH] fix: handling of None messages from notify callback (#236) Co-authored-by: Remy Noel Co-authored-by: J. Nick Koston --- src/dbus_fast/message_bus.py | 6 +++--- tests/client/test_aio.py | 26 ++++++++++++++++++++++++++ tests/client/test_methods.py | 2 ++ 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 tests/client/test_aio.py diff --git a/src/dbus_fast/message_bus.py b/src/dbus_fast/message_bus.py index 2fe9af7..5761524 100644 --- a/src/dbus_fast/message_bus.py +++ b/src/dbus_fast/message_bus.py @@ -1194,7 +1194,7 @@ class BaseMessageBus: logging.error( f'add match request failed. match="{self._name_owner_match_rule}", {err}' ) - if msg.message_type == MessageType.ERROR: + elif msg.message_type == MessageType.ERROR: logging.error( f'add match request failed. match="{self._name_owner_match_rule}", {msg.body[0]}' ) @@ -1228,7 +1228,7 @@ class BaseMessageBus: def add_match_notify(msg: Message, err: Optional[Exception]) -> None: if err: logging.error(f'add match request failed. match="{match_rule}", {err}') - if msg.message_type == MessageType.ERROR: + elif msg.message_type == MessageType.ERROR: logging.error( f'add match request failed. match="{match_rule}", {msg.body[0]}' ) @@ -1267,7 +1267,7 @@ class BaseMessageBus: logging.error( f'remove match request failed. match="{match_rule}", {err}' ) - if msg.message_type == MessageType.ERROR: + elif msg.message_type == MessageType.ERROR: logging.error( f'remove match request failed. match="{match_rule}", {msg.body[0]}' ) diff --git a/tests/client/test_aio.py b/tests/client/test_aio.py new file mode 100644 index 0000000..5e4d5e5 --- /dev/null +++ b/tests/client/test_aio.py @@ -0,0 +1,26 @@ +import pytest + +from dbus_fast import aio +from dbus_fast.service import ServiceInterface + + +class ExampleInterface(ServiceInterface): + def __init__(self): + super().__init__("test.interface") + + +@pytest.mark.asyncio +async def test_fast_disconnect(): + bus_name = "aio.client.test.methods" + + bus = await aio.MessageBus().connect() + bus2 = await aio.MessageBus().connect() + await bus.request_name(bus_name) + service_interface = ExampleInterface() + bus.export("/test/path", service_interface) + introspection = await bus2.introspect(bus_name, "/test/path") + bus2.get_proxy_object(bus_name, "/test/path", introspection) + bus2.disconnect() + bus.disconnect() + await bus.wait_for_disconnect() + await bus2.wait_for_disconnect() diff --git a/tests/client/test_methods.py b/tests/client/test_methods.py index 66e05fe..2ea9dff 100644 --- a/tests/client/test_methods.py +++ b/tests/client/test_methods.py @@ -121,6 +121,8 @@ async def test_aio_proxy_object(): bus.disconnect() bus2.disconnect() + await bus.wait_for_disconnect() + await bus2.wait_for_disconnect() @pytest.mark.skipif(