flatpak / libportal

libportal - Flatpak portal library
https://libportal.org
GNU Lesser General Public License v3.0
82 stars 40 forks source link

most inputcapture tests failing - dbusmock assert on trying to spawn a server for an already taken name #141

Closed prahal closed 9 months ago

prahal commented 10 months ago

I made PR #140 based on the clue that calling setup_daemon twice was the issue.

One of the 13 tests that fails output is:

=================================== FAILURES ===================================
_______________________ TestInputCapture.test_activated ________________________

self = <pyportaltest.test_inputcapture.TestInputCapture testMethod=test_activated>

    def test_activated(self):
        """
        Test the Activated signal
        """
        params = {
            "eis-serial": 123,
            "activated-after": 20,
            "activated-barrier": 1,
            "activated-position": (10.0, 20.0),
            "deactivated-after": 20,
            "deactivated-position": (20.0, 30.0),
        }
        self.setup_daemon(params)

>       setup = self.create_session_with_barriers(params)

pyportaltest/test_inputcapture.py:481: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
pyportaltest/test_inputcapture.py:59: in create_session_with_barriers
    self.setup_daemon(params)
pyportaltest/__init__.py:108: in setup_daemon
    self.p_mock, self.obj_portal = self.spawn_server_template(
/usr/lib/python3/dist-packages/dbusmock/testcase.py:438: in spawn_server_template
    server = SpawnedMock.spawn_with_template(template, parameters, bustype, stdout, stderr=None)
/usr/lib/python3/dist-packages/dbusmock/testcase.py:614: in spawn_with_template
    server = SpawnedMock.spawn_for_name(module.BUS_NAME, module.MAIN_OBJ, interface_name, bustype, stdout, stderr)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

cls = <class 'dbusmock.testcase.SpawnedMock'>
name = 'org.freedesktop.portal.Desktop'
path = '/org/freedesktop/portal/desktop'
interface = 'org.freedesktop.portal.InputCapture'
bustype = <BusType.SESSION: 'session'>, stdout = -1, stderr = None

    @classmethod
    def spawn_for_name(
        cls,
        name: str,
        path: str,
        interface: str,
        bustype: BusType = BusType.SESSION,
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
    ) -> "SpawnedMock":
        """Run a DBusMockObject instance in a separate process

        The daemon will terminate automatically when the D-Bus that it connects
        to goes down.  If that does not happen (e. g. you test on the actual
        system/session bus), you need to kill it manually.

        This function blocks until the spawned DBusMockObject is ready and
        listening on the bus.

        By default, stdout and stderr of the spawned process is available via the
        SpawnedMock.stdout and SpawnedMock.stderr properties on the returned object.
        """
        argv = [sys.executable, "-m", "dbusmock", f"--{bustype.value}", name, path, interface]
        bus = bustype.get_connection()
        if bus.name_has_owner(name):
>           raise AssertionError(f"Trying to spawn a server for name {name} but it is already owned!")
E           AssertionError: Trying to spawn a server for name org.freedesktop.portal.Desktop but it is already owned!

/usr/lib/python3/dist-packages/dbusmock/testcase.py:559: AssertionError
----------------------------- Captured stdout call -----------------------------
signal time=1705154704.643778 sender=org.freedesktop.DBus -> destination=:1.3 serial=2 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameAcquired
   string ":1.3"
signal time=1705154704.643832 sender=org.freedesktop.DBus -> destination=:1.3 serial=4 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameLost
   string ":1.3"
method call time=1705154704.645333 sender=:1.4 -> destination=org.freedesktop.DBus serial=1 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=Hello
method return time=1705154704.645357 sender=org.freedesktop.DBus -> destination=:1.4 serial=1 reply_serial=1
   string ":1.4"
signal time=1705154704.645372 sender=org.freedesktop.DBus -> destination=(null destination) serial=5 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameOwnerChanged
   string ":1.4"
   string ""
   string ":1.4"
signal time=1705154704.645396 sender=org.freedesktop.DBus -> destination=:1.4 serial=2 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameAcquired
   string ":1.4"
method call time=1705154704.645496 sender=:1.4 -> destination=org.freedesktop.DBus serial=2 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameHasOwner
   string "org.freedesktop.portal.Desktop"
method return time=1705154704.645514 sender=org.freedesktop.DBus -> destination=:1.4 serial=3 reply_serial=2
   boolean true
----------------------------- Captured stderr call -----------------------------
DEBUG | templates.inputcapture: Loading parameters: dbus.Dictionary({dbus.String('eis-serial'): dbus.Int32(123, variant_level=1), dbus.String('activated-after'): dbus.Int32(20, variant_level=1), dbus.String('activated-barrier'): dbus.Int32(1, variant_level=1), dbus.String('activated-position'): dbus.Struct((dbus.Double(10.0), dbus.Double(20.0)), signature=None, variant_level=1), dbus.String('deactivated-after'): dbus.Int32(20, variant_level=1), dbus.String('deactivated-position'): dbus.Struct((dbus.Double(20.0), dbus.Double(30.0)), signature=None, variant_level=1)}, signature=dbus.Signature('sv'))
dbus-daemon[27162]: [session uid=1000 pid=27162] Connection :1.3 (uid=1000 pid=27178 comm="dbus-monitor --session") became a monitor.
dbus-daemon[27162]: [session uid=1000 pid=27162] Monitoring connection :1.3 closed.
prahal commented 9 months ago

Fixed by the merge of PR #140