[tracker/sam/functional-tests-quiet: 8/15] squash! WIP: functional-tests: Start daemons through D-Bus autolaunch



commit 2b626d805b9d70380c32f50abc27917694a7bcf4
Author: Sam Thursfield <sam afuera me uk>
Date:   Thu Aug 29 18:02:11 2019 +0300

    squash! WIP: functional-tests: Start daemons through D-Bus autolaunch

 tests/functional-tests/configuration.py |  6 +++++-
 tests/functional-tests/storetest.py     | 28 +++++++++++++++++-----------
 utils/trackertestutils/dbusdaemon.py    |  1 +
 utils/trackertestutils/helpers.py       | 16 ++++++++++------
 4 files changed, 33 insertions(+), 18 deletions(-)
---
diff --git a/tests/functional-tests/configuration.py b/tests/functional-tests/configuration.py
index 7bc96bec4..75d11676d 100644
--- a/tests/functional-tests/configuration.py
+++ b/tests/functional-tests/configuration.py
@@ -39,13 +39,17 @@ TEST_ONTOLOGIES_DIR = str(pathlib.Path(__file__).parent.joinpath('test-ontologie
 disableJournal = bool(config['disableJournal'])
 
 
-def test_environment():
+def test_environment(tmpdir):
     return {
         'DCONF_PROFILE': config['TEST_DCONF_PROFILE'],
         'GSETTINGS_SCHEMA_DIR': config['TEST_GSETTINGS_SCHEMA_DIR'],
         'TRACKER_DB_ONTOLOGIES_DIR': config['TEST_ONTOLOGIES_DIR'],
         'TRACKER_LANGUAGE_STOP_WORDS_DIR': config['TEST_LANGUAGE_STOP_WORDS_DIR'],
         'TRACKER_TEST_DOMAIN_ONTOLOGY_RULE': config['TEST_DOMAIN_ONTOLOGY_RULE'],
+        'XDG_CACHE_HOME': os.path.join(tmpdir, 'cache'),
+        'XDG_CONFIG_HOME': os.path.join(tmpdir, 'config'),
+        'XDG_DATA_HOME': os.path.join(tmpdir, 'data'),
+        'XDG_RUNTIME_DIR': os.path.join(tmpdir, 'run'),
     }
 
 
diff --git a/tests/functional-tests/storetest.py b/tests/functional-tests/storetest.py
index 551bb617c..425b1d71f 100644
--- a/tests/functional-tests/storetest.py
+++ b/tests/functional-tests/storetest.py
@@ -19,6 +19,7 @@
 #
 
 import os
+import tempfile
 import time
 import unittest as ut
 
@@ -35,17 +36,22 @@ class CommonTrackerStoreTest (ut.TestCase):
 
     @classmethod
     def setUpClass(self):
-        extra_env = cfg.test_environment()
-        extra_env['LC_COLLATE'] = 'en_GB.utf8'
-
-        self.sandbox = trackertestutils.helpers.TrackerDBusSandbox(
-            dbus_daemon_config_file=cfg.TEST_DBUS_DAEMON_CONFIG_FILE, extra_env=extra_env)
-        self.sandbox.start()
-
-        self.tracker = trackertestutils.helpers.StoreHelper(
-            self.sandbox.get_connection())
-        self.tracker.wait_for_ready()
-        self.tracker.start_watching_updates()
+        tmpdir = tempfile.mkdtemp(prefix='tracker-test-')
+
+        try:
+            extra_env = cfg.test_environment(tmpdir)
+            extra_env['LC_COLLATE'] = 'en_GB.utf8'
+
+            self.sandbox = trackertestutils.helpers.TrackerDBusSandbox(
+                dbus_daemon_config_file=cfg.TEST_DBUS_DAEMON_CONFIG_FILE, extra_env=extra_env)
+            self.sandbox.start()
+
+            self.tracker = trackertestutils.helpers.StoreHelper(
+                self.sandbox.get_connection())
+            self.tracker.start_and_wait_for_ready()
+            self.tracker.start_watching_updates()
+        except Exception as e:
+            shutil.rmtree(tmpdir)
 
     @classmethod
     def tearDownClass(self):
diff --git a/utils/trackertestutils/dbusdaemon.py b/utils/trackertestutils/dbusdaemon.py
index ddf3fd136..3b336d696 100644
--- a/utils/trackertestutils/dbusdaemon.py
+++ b/utils/trackertestutils/dbusdaemon.py
@@ -107,6 +107,7 @@ class DBusDaemon:
                 dbus_command += ['--config-file=' + config_file]
             else:
                 dbus_command += ['--session']
+            log.debug("Running: %s", dbus_command)
             self.process = subprocess.Popen(
                 dbus_command, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
 
diff --git a/utils/trackertestutils/helpers.py b/utils/trackertestutils/helpers.py
index 71ad68a88..12fa780c2 100644
--- a/utils/trackertestutils/helpers.py
+++ b/utils/trackertestutils/helpers.py
@@ -77,24 +77,28 @@ class StoreHelper():
         self.bus = dbus_connection
 
         self.resources = Gio.DBusProxy.new_sync(
-            self.bus, Gio.DBusProxyFlags.NONE, None,
+            self.bus, Gio.DBusProxyFlags.DO_NOT_AUTO_START_AT_CONSTRUCTION, None,
             self.TRACKER_BUSNAME, self.TRACKER_OBJ_PATH, self.RESOURCES_IFACE)
 
         self.backup_iface = Gio.DBusProxy.new_sync(
-            self.bus, Gio.DBusProxyFlags.NONE, None,
+            self.bus, Gio.DBusProxyFlags.DO_NOT_AUTO_START_AT_CONSTRUCTION, None,
             self.TRACKER_BUSNAME, self.TRACKER_BACKUP_OBJ_PATH, self.BACKUP_IFACE)
 
         self.stats_iface = Gio.DBusProxy.new_sync(
-            self.bus, Gio.DBusProxyFlags.NONE, None,
+            self.bus, Gio.DBusProxyFlags.DO_NOT_AUTO_START_AT_CONSTRUCTION, None,
             self.TRACKER_BUSNAME, self.TRACKER_STATS_OBJ_PATH, self.STATS_IFACE)
 
         self.status_iface = Gio.DBusProxy.new_sync(
-            self.bus, Gio.DBusProxyFlags.NONE, None,
+            self.bus, Gio.DBusProxyFlags.DO_NOT_AUTO_START_AT_CONSTRUCTION, None,
             self.TRACKER_BUSNAME, self.TRACKER_STATUS_OBJ_PATH, self.STATUS_IFACE)
 
-    def wait_for_ready(self):
+    def start_and_wait_for_ready(self):
+        # The daemon is autostarted as soon as a method is called.
+        #
+        # We set a big timeout to avoid interfering when a daemon is being
+        # interactively debugged.
         self.log.debug("Calling %s.Wait() method", self.STATUS_IFACE)
-        self.status_iface.Wait()
+        self.status_iface.call_sync('Wait', None, Gio.DBusCallFlags.NONE, 1000000, None)
         self.log.debug("Ready")
 
     def start_watching_updates(self):


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