[tracker/sam/test-fixes: 5/7] trackertestutils: Fix some issues with D-Bus name changes



commit 68fe90a7b8d0d6b5c3d6f2237e4ddfc8123f7e5a
Author: Sam Thursfield <sam afuera me uk>
Date:   Wed Apr 29 01:23:41 2020 +0200

    trackertestutils: Fix some issues with D-Bus name changes
    
    The stop_miner_fs() function is now stop_daemon() and the caller
    supplies the busname. This makes it more flexible and avoids hardcoding
    the miner-fs busname.

 utils/trackertestutils/helpers.py | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)
---
diff --git a/utils/trackertestutils/helpers.py b/utils/trackertestutils/helpers.py
index a8f695665..afcee7e35 100644
--- a/utils/trackertestutils/helpers.py
+++ b/utils/trackertestutils/helpers.py
@@ -38,6 +38,10 @@ from . import psutil_mini as psutil
 log = logging.getLogger(__name__)
 
 
+TRACKER_DBUS_PREFIX = 'org.freedesktop.Tracker3'
+TRACKER_MINER_FS_BUSNAME = 'org.freedesktop.Tracker3.Miner.Files'
+
+
 class AwaitException(RuntimeError):
     pass
 
@@ -489,7 +493,7 @@ class TrackerDBusSandbox:
 
         log.info("Looking for active Tracker processes on the bus")
         for busname in self.daemon.list_names_sync():
-            if busname.startswith('org.freedesktop.Tracker3'):
+            if busname.startswith(TRACKER_DBUS_PREFIX):
                 pid = self.daemon.get_connection_unix_process_id_sync(busname)
                 if pid is not None:
                     tracker_processes.append(pid)
@@ -511,14 +515,21 @@ class TrackerDBusSandbox:
         log.info("Stopping D-Bus daemon for sandbox.")
         self.daemon.stop()
 
-    def stop_miner_fs(self):
-        log.info("Stopping tracker-miner-fs process.")
-        pid = self.daemon.get_connection_unix_process_id_sync('org.freedesktop.Tracker1.Miner.Files')
+    def stop_daemon(self, busname):
+        """Stops the daemon that owns 'busname'.
+
+        This can be used if you want to force the miner-fs to exit, for
+        example.
+
+        """
+        log.info("Stopping daemon process that owns %s.", busname)
+        pid = self.daemon.get_connection_unix_process_id_sync(busname)
         if pid:
             os.kill(pid, signal.SIGTERM)
             psutil.wait_pid(pid)
+            log.info("Process %i has stopped.", pid)
         else:
-            log.info("tracker-miner-fs process was not found on the message bus.")
+            log.info("Couldn't find a process owning %s.", busname)
 
     def get_connection(self):
         return self.daemon.get_connection()


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