[tracker/sam/test-fixes: 3/7] trackertestutils: Add debugging hint



commit fa4aad3138933805c56b131b99f318a8553d0f68
Author: Sam Thursfield <sam afuera me uk>
Date:   Mon Apr 27 19:23:53 2020 +0200

    trackertestutils: Add debugging hint
    
    I didn't make this a proper feature, but it's a clue that you can
    turn on D-Bus monitoring inside the sandbox.

 utils/trackertestutils/dbusdaemon.py | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)
---
diff --git a/utils/trackertestutils/dbusdaemon.py b/utils/trackertestutils/dbusdaemon.py
index 59de04ecf..e55c03595 100644
--- a/utils/trackertestutils/dbusdaemon.py
+++ b/utils/trackertestutils/dbusdaemon.py
@@ -113,6 +113,9 @@ class DBusDaemon:
         log.debug("Pinging the new D-Bus daemon...")
         self.ping_sync()
 
+        # Uncomment to output D-Bus events to the console.
+        #monitor = subprocess.Popen(['dbus-monitor', '--address', self.address])
+
     def stop(self):
         if self.process:
             log.debug("  Stopping DBus daemon")
@@ -179,11 +182,20 @@ class DBusDaemon:
     def get_connection_unix_process_id_sync(self, name):
         """Get the process ID for one of the names connected to the bus."""
         conn = self.get_connection()
-        result = conn.call_sync('org.freedesktop.DBus',
-                                '/org/freedesktop/DBus',
-                                'org.freedesktop.DBus',
-                                'GetConnectionUnixProcessID',
-                                GLib.Variant('(s)', [name]),
-                                GLib.VariantType('(u)'),
-                                Gio.DBusCallFlags.NONE, -1, None)
-        return result[0]
+        try:
+            result = conn.call_sync('org.freedesktop.DBus',
+                                    '/org/freedesktop/DBus',
+                                    'org.freedesktop.DBus',
+                                    'GetConnectionUnixProcessID',
+                                    GLib.Variant('(s)', [name]),
+                                    GLib.VariantType('(u)'),
+                                    Gio.DBusCallFlags.NONE, -1, None)
+            return result[0]
+        except GLib.GError as e:
+            if e.message.startswith('GDBus.Error:org.freedesktop.DBus.Error.NameHasNoOwner'):
+                # This can happen if a daemon disconnects between when we call
+                # list_names_sync() and when we query its PID.
+                log.debug("Received %s", e)
+                return None
+            else:
+                raise


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]