[tracker-miners/sam/functional-tests-shared: 15/15] functional-tests: Clean up TrackerSystemAbstraction code
- From: Sam Thursfield <sthursfield src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker-miners/sam/functional-tests-shared: 15/15] functional-tests: Clean up TrackerSystemAbstraction code
- Date: Fri, 23 Aug 2019 09:43:54 +0000 (UTC)
commit ee58ed144cf727d4ddca5e9286a525c7fe4f81dc
Author: Sam Thursfield <sam afuera me uk>
Date: Wed Aug 21 23:39:42 2019 +0100
functional-tests: Clean up TrackerSystemAbstraction code
In particular, stop modifying os.environ() directly. We now append to
the environment instead.
tests/functional-tests/applicationstest.py | 4 +-
tests/functional-tests/minertest.py | 19 ++--
tests/functional-tests/system.py | 134 +++++++++--------------------
tests/functional-tests/writebacktest.py | 4 +-
4 files changed, 54 insertions(+), 107 deletions(-)
---
diff --git a/tests/functional-tests/applicationstest.py b/tests/functional-tests/applicationstest.py
index efb481a84..2d7077589 100644
--- a/tests/functional-tests/applicationstest.py
+++ b/tests/functional-tests/applicationstest.py
@@ -106,8 +106,8 @@ class CommonTrackerApplicationTest (ut.TestCase):
"tracker-tests",
"test-apps-data")
- self.system = TrackerSystemAbstraction()
- self.system.tracker_all_testing_start(CONF_OPTIONS)
+ self.system = TrackerSystemAbstraction(settings=CONF_OPTIONS)
+ self.system.tracker_all_testing_start()
self.tracker = self.system.store
@classmethod
diff --git a/tests/functional-tests/minertest.py b/tests/functional-tests/minertest.py
index 27a4446f1..96710c0a4 100644
--- a/tests/functional-tests/minertest.py
+++ b/tests/functional-tests/minertest.py
@@ -60,21 +60,18 @@ class CommonTrackerMinerTest (ut.TestCase):
'org.freedesktop.Tracker.Store': {
'graphupdated-delay': GLib.Variant('i', 100)
}
+ 'org.freedesktop.Tracker.Miner.Files': {
+ 'index-recursive-directories': GLib.Variant.new_strv([self.indexed_dir]),
+ 'index-single-directories': GLib.Variant.new_strv([]),
+ 'index-optical-discs': GLib.Variant.new_boolean(False),
+ 'index-removable-devices': GLib.Variant.new_boolean(False),
+ 'throttle': GLib.Variant.new_int32(5),
+ }
}
)
- config = {
- 'org.freedesktop.Tracker.Miner.Files': {
- 'index-recursive-directories': GLib.Variant.new_strv([self.indexed_dir]),
- 'index-single-directories': GLib.Variant.new_strv([]),
- 'index-optical-discs': GLib.Variant.new_boolean(False),
- 'index-removable-devices': GLib.Variant.new_boolean(False),
- 'throttle': GLib.Variant.new_int32(5),
- }
- }
-
try:
- self.system.tracker_miner_fs_testing_start(config)
+ self.system.tracker_miner_fs_testing_start()
except RuntimeError as e:
self.fail(e)
diff --git a/tests/functional-tests/system.py b/tests/functional-tests/system.py
index f7f4b203b..94649ace1 100644
--- a/tests/functional-tests/system.py
+++ b/tests/functional-tests/system.py
@@ -61,8 +61,10 @@ class MinerFsHelper (trackertestutils.helpers.Helper):
self._previous_status = None
self._target_wakeup_count = None
- def start(self):
- trackertestutils.helpers.Helper.start(self, ['--initial-sleep=0'])
+ def start(self, command_args=None, extra_env=None):
+ command_args = command_args or []
+
+ trackertestutils.helpers.Helper.start(self, command_args + ['--initial-sleep=0'], extra_env)
self.miner_fs = Gio.DBusProxy.new_sync(
self.bus, Gio.DBusProxyFlags.DO_NOT_AUTO_START, None,
@@ -155,15 +157,20 @@ class WritebackHelper (trackertestutils.helpers.Helper):
class TrackerSystemAbstraction (object):
def __init__(self, settings=None, ontodir=None):
- self._basedir = None
-
self.extractor = None
self.miner_fs = None
self.store = None
self.writeback = None
- self.set_up_environment(settings=settings, ontodir=ontodir)
- self.store = None
+ self._dconf_settings = settings
+ self._ontologies_dir = ontodir
+
+ self._basedir = tempfile.mkdtemp()
+
+ self._dirs = {
+ "XDG_DATA_HOME": self.xdg_data_home(),
+ "XDG_CACHE_HOME": self.xdg_cache_home()
+ }
def xdg_data_home(self):
return os.path.join(self._basedir, 'data')
@@ -171,121 +178,64 @@ class TrackerSystemAbstraction (object):
def xdg_cache_home(self):
return os.path.join(self._basedir, 'cache')
- def set_up_environment(self, settings=None, ontodir=None):
- """
- Sets up the XDG_*_HOME variables and make sure the directories exist
+ def environment(self):
+ """Returns extra environment variables to set for the daemons."""
+ extra_env = {}
- Settings should be a dict mapping schema names to dicts that hold the
- settings that should be changed in those schemas. The contents dicts
- should map key->value, where key is a key name and value is a suitable
- GLib.Variant instance.
- """
+ for var, directory in self._dirs.items():
+ extra_env[var] = directory
- self._basedir = tempfile.mkdtemp()
+ if self._ontologies_dir:
+ extra_env["TRACKER_DB_ONTOLOGIES_DIR"] = self._ontologies_dir
- self._dirs = {
- "XDG_DATA_HOME": self.xdg_data_home(),
- "XDG_CACHE_HOME": self.xdg_cache_home()
- }
+ for var, value in TEST_ENV_VARS.items():
+ extra_env[var] = value
- for var, directory in list(self._dirs.items()):
+ return extra_env
+
+ def _create_dirs(self):
+ # Make sure the XDG_*_HOME directories exist
+ for var, directory in self._dirs.items():
os.makedirs(directory)
os.makedirs(os.path.join(directory, 'tracker'))
- os.environ[var] = directory
-
- if ontodir:
- os.environ["TRACKER_DB_ONTOLOGIES_DIR"] = ontodir
- for var, value in TEST_ENV_VARS.items():
- os.environ[var] = value
-
- # Previous loop should have set DCONF_PROFILE to the test location
- if settings is not None:
- self._apply_settings(settings)
-
- def _apply_settings(self, settings):
- for schema_name, contents in settings.items():
+ def _setup_dconf(self):
+ # Initialize the DConf profile with our settings.
+ # (The profile we use is defined in meson.build by setting
+ # DCONF_PROFILE in the test environment).
+ for schema_name, contents in self._dconf_settings.items():
dconf = trackertestutils.dconf.DConfClient(schema_name)
dconf.reset()
for key, value in contents.items():
dconf.write(key, value)
- def tracker_store_testing_start(self, confdir=None, ontodir=None):
- """
- Stops any previous instance of the store, calls set_up_environment,
- and starts a new instances of the store
- """
- self.set_up_environment(confdir, ontodir)
-
- self.store = trackertestutils.helpers.StoreHelper(cfg.TRACKER_STORE_PATH)
- self.store.start()
-
- def tracker_store_start(self):
- self.store.start()
-
- def tracker_store_restart_with_new_ontologies(self, ontodir):
- self.store.stop()
- if ontodir:
- log.debug("[Conf] Setting %s - %s", "TRACKER_DB_ONTOLOGIES_DIR", ontodir)
- os.environ["TRACKER_DB_ONTOLOGIES_DIR"] = ontodir
- try:
- self.store.start()
- except GLib.Error as e:
- raise UnableToBootException("Unable to boot the store \n(" + str(e) + ")")
-
- def tracker_store_prepare_journal_replay(self):
- db_location = os.path.join(self.xdg_cache_home(), "tracker", "meta.db")
- os.unlink(db_location)
-
- lockfile = os.path.join(self.xdg_data_home(), "tracker", "data", ".ismeta.running")
- f = open(lockfile, 'w')
- f.write(" ")
- f.close()
-
- def tracker_store_corrupt_dbs(self):
- for filename in ["meta.db", "meta.db-wal"]:
- db_path = os.path.join(self.xdg_cache_home(), "tracker", filename)
- f = open(db_path, "w")
- for i in range(0, 100):
- f.write("Some stupid content... hohohoho, not a sqlite file anymore!\n")
- f.close()
-
- def tracker_store_remove_journal(self):
- db_location = os.path.join(self.xdg_data_home(), "tracker", "data")
- shutil.rmtree(db_location)
- os.mkdir(db_location)
-
- def tracker_store_remove_dbs(self):
- db_location = os.path.join(self.xdg_cache_home(), "tracker")
- shutil.rmtree(db_location)
- os.mkdir(db_location)
-
- def tracker_miner_fs_testing_start(self, confdir=None):
+ def tracker_miner_fs_testing_start(self):
"""
Stops any previous instance of the store and miner, calls set_up_environment,
and starts a new instance of the store and miner-fs
"""
- self.set_up_environment(confdir, None)
+ self._create_dirs()
+ self._setup_dconf()
# Start also the store. DBus autoactivation ignores the env variables.
self.store = trackertestutils.helpers.StoreHelper(cfg.TRACKER_STORE_PATH)
- self.store.start()
+ self.store.start(extra_env=self.environment())
self.extractor = ExtractorHelper(cfg.TRACKER_EXTRACT_PATH)
- self.extractor.start()
+ self.extractor.start(extra_env=self.environment())
self.miner_fs = MinerFsHelper(cfg.TRACKER_MINER_FS_PATH)
- self.miner_fs.start()
+ self.miner_fs.start(extra_env=self.environment())
- def tracker_writeback_testing_start(self, confdir=None):
+ def tracker_writeback_testing_start(self):
# Start the miner-fs (and store) and then the writeback process
- self.tracker_miner_fs_testing_start(confdir)
+ self.tracker_miner_fs_testing_start()
self.writeback = WritebackHelper(cfg.TRACKER_WRITEBACK_PATH)
self.writeback.start()
- def tracker_all_testing_start(self, confdir=None):
+ def tracker_all_testing_start(self):
# This will start all miner-fs, store and writeback
- self.tracker_writeback_testing_start(confdir)
+ self.tracker_writeback_testing_start()
def finish(self):
"""
diff --git a/tests/functional-tests/writebacktest.py b/tests/functional-tests/writebacktest.py
index d8feb7d42..b9d436660 100644
--- a/tests/functional-tests/writebacktest.py
+++ b/tests/functional-tests/writebacktest.py
@@ -59,8 +59,8 @@ class CommonTrackerWritebackTest (ut.TestCase):
}
}
- self.system = TrackerSystemAbstraction()
- self.system.tracker_writeback_testing_start(CONF_OPTIONS)
+ self.system = TrackerSystemAbstraction(CONF_OPTIONS)
+ self.system.tracker_writeback_testing_start()
self.tracker = self.system.store
self.extractor = self.system.extractor
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]