Skip to content

Commit

Permalink
test(client): test early disconnect
Browse files Browse the repository at this point in the history
The test does not fails but outputs the following erroneous logs:

  ERROR    root:message_bus.py:1194 add match request failed. match="sender='org.freedesktop.DBus',interface='org.freedesktop.DBus',path='/org/freedesktop/DBus',member='NameOwnerChanged'",
  WARNING  root:message_bus.py:584 a message handler threw an exception on shutdown
  Traceback (most recent call last):
    File "/home/mocramis/misc/dbus-fast/src/dbus_fast/aio/message_reader.py", line 22, in _message_reader
      message = unmarshaller._unmarshall()
    File "/home/mocramis/misc/dbus-fast/src/dbus_fast/_private/unmarshaller.py", line 742, in _unmarshall
      self._read_header()
    File "/home/mocramis/misc/dbus-fast/src/dbus_fast/_private/unmarshaller.py", line 611, in _read_header
      self._read_to_pos(HEADER_SIGNATURE_SIZE)
    File "/home/mocramis/misc/dbus-fast/src/dbus_fast/_private/unmarshaller.py", line 366, in _read_to_pos
      self._read_sock_without_fds(pos)
    File "/home/mocramis/misc/dbus-fast/src/dbus_fast/_private/unmarshaller.py", line 329, in _read_sock_without_fds
      raise EOFError()
  EOFError

  During handling of the above exception, another exception occurred:

  Traceback (most recent call last):
    File "/home/mocramis/misc/dbus-fast/src/dbus_fast/message_bus.py", line 582, in _finalize
      handler(None, err)
    File "/home/mocramis/misc/dbus-fast/src/dbus_fast/message_bus.py", line 737, in _reply_notify
      callback(reply, err)
    File "/home/mocramis/misc/dbus-fast/src/dbus_fast/message_bus.py", line 1197, in add_match_notify
      if msg.message_type == MessageType.ERROR:
  AttributeError: 'NoneType' object has no attribute 'message_type'

However, trying to capture those logs seems to prevent the race
condition from happening. Therefore, we just run the test for coverage.
  • Loading branch information
Remy Noel committed Sep 4, 2023
1 parent d449029 commit 2e5f27b
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/client/test_aio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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()

0 comments on commit 2e5f27b

Please sign in to comment.