[tracker/sam/functional-tests-quiet] funcional-tests: Terminate Tracker processes before the message bus



commit db529222866381317161fa9234691ebceb6a3c7b
Author: Sam Thursfield <sam afuera me uk>
Date:   Tue Sep 10 12:14:35 2019 +0200

    funcional-tests: Terminate Tracker processes before the message bus
    
    This reduces the volume of criticals like this that we see in the log
    output:
    
        (tracker-miner-fs:14955): GLib-GIO-CRITICAL **: 11:38:40.386: Error while sending AddMatch() message: 
The connection is closed
    
    I did still see one test that output a bunch of similar criticals from
    tracker-extract.

 utils/trackertestutils/dbusdaemon.py | 24 ++++++++++++++++++++++++
 utils/trackertestutils/helpers.py    | 21 +++++++++++++++++++++
 2 files changed, 45 insertions(+)
---
diff --git a/utils/trackertestutils/dbusdaemon.py b/utils/trackertestutils/dbusdaemon.py
index e937cd05b..4633fa176 100644
--- a/utils/trackertestutils/dbusdaemon.py
+++ b/utils/trackertestutils/dbusdaemon.py
@@ -17,6 +17,7 @@
 
 
 from gi.repository import Gio
+from gi.repository import GLib
 
 import logging
 import os
@@ -192,6 +193,29 @@ class DBusDaemon:
         self.stop()
 
     def ping_sync(self):
+        """Call the daemon Ping() method to check that it is alive."""
         self._gdbus_connection.call_sync(
             'org.freedesktop.DBus', '/', 'org.freedesktop.DBus', 'GetId',
             None, None, Gio.DBusCallFlags.NONE, 10000, None)
+
+    def list_names_sync(self):
+        """Get the name of every client connected to the bus."""
+        conn = self.get_connection()
+        result = conn.call_sync('org.freedesktop.DBus',
+                                '/org/freedesktop/DBus',
+                                'org.freedesktop.DBus', 'ListNames', None,
+                                GLib.VariantType('(as)'),
+                                Gio.DBusCallFlags.NONE, -1, None)
+        return result[0]
+
+    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]
diff --git a/utils/trackertestutils/helpers.py b/utils/trackertestutils/helpers.py
index 45fa67242..5b9431e10 100644
--- a/utils/trackertestutils/helpers.py
+++ b/utils/trackertestutils/helpers.py
@@ -24,6 +24,7 @@ from gi.repository import GLib
 import atexit
 import logging
 import os
+import signal
 
 from . import dbusdaemon
 from . import mainloop
@@ -463,6 +464,26 @@ class TrackerDBusSandbox:
         self.daemon.start_if_needed(self.dbus_daemon_config_file, env=env)
 
     def stop(self):
+        tracker_processes = []
+
+        log.info("Looking for active Tracker processes on the bus")
+        for busname in self.daemon.list_names_sync():
+            if busname.startswith('org.freedesktop.Tracker1'):
+                pid = self.daemon.get_connection_unix_process_id_sync(busname)
+                tracker_processes.append(pid)
+
+        log.info("Stopping %i Tracker processes", len(tracker_processes))
+        for pid in tracker_processes:
+            os.kill(pid, signal.SIGTERM)
+            status = os.waitpid(pid, 0)
+            log.debug("  Got status: %s", str(status))
+
+        # We need to wait until Tracker processes have stopped before we
+        # terminate the D-Bus daemon, otherwise lots of criticals like this
+        # appear in the log output:
+        #
+        #  (tracker-miner-fs:14955): GLib-GIO-CRITICAL **: 11:38:40.386: Error  while sending AddMatch() 
message: The connection is closed
+
         log.info("Stopping D-Bus daemon for sandbox.")
         self.daemon.stop()
 


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