[tracker-miners/sam/file-processed-signal: 10/10] Fix functional tests



commit 13919513eae6912a1f403627e77830234b1993bf
Author: Sam Thursfield <sam afuera me uk>
Date:   Sun Apr 5 12:37:53 2020 +0200

    Fix functional tests

 tests/functional-tests/fixtures.py        |  6 ++++++
 tests/functional-tests/miner-basic.py     |  6 ------
 tests/functional-tests/miner-on-demand.py | 16 ++++++++++++----
 3 files changed, 18 insertions(+), 10 deletions(-)
---
diff --git a/tests/functional-tests/fixtures.py b/tests/functional-tests/fixtures.py
index 946519e0b..55281aff9 100644
--- a/tests/functional-tests/fixtures.py
+++ b/tests/functional-tests/fixtures.py
@@ -110,6 +110,12 @@ class TrackerMinerTest(ut.TestCase):
         self.sandbox.start()
 
         try:
+            # It's important that this directory exists BEFORE we start Tracker:
+            # it won't monitor an indexing root for changes if it doesn't exist,
+            # it'll silently ignore it instead. See the tracker_crawler_start()
+            # function.
+            os.makedirs(self.indexed_dir, exist_ok=True)
+
             for schema_name, contents in self.config().items():
                 dconf = trackertestutils.dconf.DConfClient(self.sandbox)
                 for key, value in contents.items():
diff --git a/tests/functional-tests/miner-basic.py b/tests/functional-tests/miner-basic.py
index edd7414ea..00d1c1aff 100755
--- a/tests/functional-tests/miner-basic.py
+++ b/tests/functional-tests/miner-basic.py
@@ -65,12 +65,6 @@ class MinerCrawlTest(fixtures.TrackerMinerTest):
             raise
 
     def create_test_data(self):
-        # It's important that this directory exists BEFORE we start Tracker:
-        # it won't monitor an indexing root for changes if it doesn't exist,
-        # it'll silently ignore it instead. See the tracker_crawler_start()
-        # function.
-        os.makedirs(self.indexed_dir, exist_ok=True)
-
         monitored_files = [
             'test-monitored/file1.txt',
             'test-monitored/dir1/file2.txt',
diff --git a/tests/functional-tests/miner-on-demand.py b/tests/functional-tests/miner-on-demand.py
index 94598ba5a..580e5a93c 100755
--- a/tests/functional-tests/miner-on-demand.py
+++ b/tests/functional-tests/miner-on-demand.py
@@ -78,6 +78,15 @@ class MinerOnDemandTest(fixtures.TrackerMinerTest):
             self.miner_fs.index_file('file:///test-missing')
         assert 
e.exception.message.startswith('GDBus.Error:org.freedesktop.Tracker.Miner.Files.Index.Error.FileNotFound:')
 
+    def await_failsafe_marker_inserted(self, path, timeout=configuration.DEFAULT_TIMEOUT):
+        url = path.as_uri()
+        expected = [
+            f'nie:url <{url}>',
+            'nie:dataSource tracker:extractor-failure-data-source'
+        ]
+
+        return self.tracker.await_insert('; '.join(expected), timeout=timeout)
+
     def test_index_extractor_error(self):
         """
         On-demand indexing of a file, but the extractor can't extract it.
@@ -86,12 +95,11 @@ class MinerOnDemandTest(fixtures.TrackerMinerTest):
         # This file will be processed by the mp3 or gstreamer extractor due to
         # its extension, but it's not a valid MP3.
         testfile = self.create_test_file('test-not-monitored/invalid.mp3')
-        with self.extractor.await_file_processed(testfile, False, timeout=5000):
-            self.miner_fs.index_file(testfile.as_uri())
 
         # The extractor should record the file in the store as a failure.
-        sparql = 'ASK { ?r nie:url <%s> ; nie:dataSource tracker:extractor-failure-data-source }' % 
testfile.as_uri()
-        self.assertTrue(self.tracker.ask(sparql))
+        with self.await_failsafe_marker_inserted(testfile):
+            with self.extractor.await_file_processed(testfile, False, timeout=5000):
+                self.miner_fs.index_file(testfile.as_uri())
 
     def test_index_directory_basic(self):
         """


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