[tracker/tracker-1.2] functional-tests: Partially fix writeback tests



commit caa60e4d49d2cfeebb9b50cca43f6461472438e4
Author: Sam Thursfield <sam afuera me uk>
Date:   Sun Jul 20 00:34:00 2014 +0100

    functional-tests: Partially fix writeback tests
    
    Use the new way of getting tracker-extract output, as the old way does not work.
    
    Wait for writeback to be done by waiting for the file's mtime to change, instead
    of using time.sleep().
    
    The writeback tests still fail at this point.

 tests/functional-tests/500-writeback.py            |   16 ++++++++++------
 tests/functional-tests/501-writeback-details.py    |   19 ++++++++++++++-----
 tests/functional-tests/common/utils/extractor.py   |    4 +++-
 tests/functional-tests/common/utils/helpers.py     |    5 +++++
 .../functional-tests/common/utils/writebacktest.py |   18 ++++++++++++++++--
 5 files changed, 48 insertions(+), 14 deletions(-)
---
diff --git a/tests/functional-tests/500-writeback.py b/tests/functional-tests/500-writeback.py
index cd144a7..cdd2b06 100755
--- a/tests/functional-tests/500-writeback.py
+++ b/tests/functional-tests/500-writeback.py
@@ -24,6 +24,7 @@ on the files. Note that these tests are highly platform dependant.
 import os, dbus
 import time
 
+from common.utils.extractor import get_tracker_extract_output
 from common.utils.writebacktest import CommonTrackerWritebackTest as CommonTrackerWritebackTest
 import unittest2 as ut
 from common.utils.expectedFailure import expectedFailureBug
@@ -69,6 +70,10 @@ class WritebackBasicDataTest (CommonTrackerWritebackTest):
         the @prop is used.
         """
 
+        # FIXME: filename is actually a URI! :(
+        filename_real = filename[len('file://'):]
+        initial_mtime = os.stat(filename_real).st_mtime
+
         TEST_VALUE = prop.replace (":","") + "test"
         SPARQL_TMPL = """
            INSERT { ?u %s '%s' }
@@ -76,11 +81,10 @@ class WritebackBasicDataTest (CommonTrackerWritebackTest):
         """ 
         self.__clean_property (prop, filename)
         self.tracker.update (SPARQL_TMPL % (prop, TEST_VALUE, filename))
-        
-        # There is no way to know when the operation is finished
-        time.sleep (REASONABLE_TIMEOUT)
-        
-        results = self.extractor.get_metadata (filename, mimetype)
+
+        self.wait_for_file_change(filename_real, initial_mtime)
+
+        results = get_tracker_extract_output (filename, mimetype)
         keyDict = expectedKey or prop
         self.assertIn (TEST_VALUE, results[keyDict])
         self.__clean_property (prop, filename, False)
@@ -112,7 +116,7 @@ class WritebackBasicDataTest (CommonTrackerWritebackTest):
 
         time.sleep (REASONABLE_TIMEOUT)
 
-        results = self.extractor.get_metadata (filename, mimetype)
+        results = get_tracker_extract_output (filename, mimetype)
         self.assertIn ("testTag", results ["nao:hasTag"])
 
 
diff --git a/tests/functional-tests/501-writeback-details.py b/tests/functional-tests/501-writeback-details.py
index 62da5fc..856f698 100755
--- a/tests/functional-tests/501-writeback-details.py
+++ b/tests/functional-tests/501-writeback-details.py
@@ -18,13 +18,16 @@
 # Boston, MA  02110-1301, USA.
 #
 from common.utils.writebacktest import CommonTrackerWritebackTest as CommonTrackerWritebackTest
+from common.utils.extractor import get_tracker_extract_output
 from common.utils.helpers import log
 import unittest2 as ut
 from common.utils.expectedFailure import expectedFailureBug
+import os
 import time
 
 REASONABLE_TIMEOUT = 5 # Seconds we wait for tracker-writeback to do the work
 
+
 class WritebackKeepDateTest (CommonTrackerWritebackTest):
 
     def setUp (self):
@@ -62,7 +65,12 @@ class WritebackKeepDateTest (CommonTrackerWritebackTest):
 
         log ("Waiting 2 seconds to ensure there is a noticiable difference in the timestamp")
         time.sleep (2)
-    
+
+        url = self.get_test_filename_jpeg ()
+
+        filename = url[len('file://'):]
+        initial_mtime = os.stat(filename).st_mtime
+
         # This triggers the writeback
         mark_as_favorite = """
          INSERT {
@@ -70,13 +78,14 @@ class WritebackKeepDateTest (CommonTrackerWritebackTest):
          } WHERE {
            ?u nie:url <%s> .
          }
-        """ % (self.get_test_filename_jpeg ())
+        """ % url
         self.tracker.update (mark_as_favorite)
-        log ("Setting favorite in <%s>" % (self.get_test_filename_jpeg ()))
-        time.sleep (REASONABLE_TIMEOUT)
+        log ("Setting favorite in <%s>" % url)
+
+        self.wait_for_file_change (filename, initial_mtime)
 
         # Check the value is written in the file
-        metadata = self.extractor.get_metadata (self.get_test_filename_jpeg (), "")
+        metadata = get_tracker_extract_output (filename, "")
         self.assertIn (self.favorite, metadata ["nao:hasTag"],
                        "Tag hasn't been written in the file")
         
diff --git a/tests/functional-tests/common/utils/extractor.py 
b/tests/functional-tests/common/utils/extractor.py
index 183a913..8dd0560 100644
--- a/tests/functional-tests/common/utils/extractor.py
+++ b/tests/functional-tests/common/utils/extractor.py
@@ -253,13 +253,15 @@ class ExtractorParser(object):
         return clean.strip ()
 
 
-def get_tracker_extract_output(filename):
+def get_tracker_extract_output(filename, mime_type=None):
     """
     Runs `tracker-extract --file` to extract metadata from a file.
     """
 
     tracker_extract = os.path.join (cfg.EXEC_PREFIX, 'tracker-extract')
     command = [tracker_extract, '--file', filename]
+    if mime_type is not None:
+        command.extend(['--mime', mime_type])
 
     try:
         log ('Running: %s' % ' '.join(command))
diff --git a/tests/functional-tests/common/utils/helpers.py b/tests/functional-tests/common/utils/helpers.py
index 16afa82..ab91c0a 100644
--- a/tests/functional-tests/common/utils/helpers.py
+++ b/tests/functional-tests/common/utils/helpers.py
@@ -572,6 +572,11 @@ class MinerFsHelper (Helper):
         """
         Block until the miner has finished crawling and its status becomes "Idle"
         """
+        status = self.miner_fs.GetStatus()
+        log ('Current miner FS status: %s' % status)
+
+        if status == 'Idle':
+            return
 
         self.status_match = self.bus.add_signal_receiver (self._minerfs_status_cb,
                                                           signal_name="Progress",
diff --git a/tests/functional-tests/common/utils/writebacktest.py 
b/tests/functional-tests/common/utils/writebacktest.py
index 927dad3..db756e0 100644
--- a/tests/functional-tests/common/utils/writebacktest.py
+++ b/tests/functional-tests/common/utils/writebacktest.py
@@ -78,9 +78,8 @@ class CommonTrackerWritebackTest (ut.TestCase):
             origin = os.path.join (datadir, testfile)
             log ("Copying %s -> %s" % (origin, WRITEBACK_TMP_DIR))
             shutil.copy (origin, WRITEBACK_TMP_DIR)
-            time.sleep (2)
 
-    
+
     @classmethod 
     def setUpClass (self):
         #print "Starting the daemon in test mode"
@@ -106,3 +105,18 @@ class CommonTrackerWritebackTest (ut.TestCase):
 
     def get_test_filename_png (self):
         return uri (TEST_FILE_PNG)
+
+    def get_mtime (self, filename):
+        return os.stat(filename).st_mtime
+
+    def wait_for_file_change (self, filename, initial_mtime):
+        start = time.time()
+        while time.time() < start + 5:
+            mtime = os.stat(filename).st_mtime
+            if mtime > initial_mtime:
+                return
+            time.sleep(0.2)
+
+        raise Exception(
+            "Timeout waiting for %s to be updated (mtime has not changed)" %
+            filename)


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