[tracker/sam/functional-test-fixes: 1/30] functional-tests: Writeback faff



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

    functional-tests: Writeback faff
    
    Writeback tests still fail; mtime related?

 tests/functional-tests/500-writeback.py            |   16 ++++++++++------
 tests/functional-tests/501-writeback-details.py    |   18 +++++++++++++-----
 tests/functional-tests/common/utils/extractor.py   |    4 +++-
 tests/functional-tests/common/utils/helpers.py     |    5 +++++
 .../functional-tests/common/utils/writebacktest.py |   20 ++++++++++++++++++--
 5 files changed, 49 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..bd0f15b 100755
--- a/tests/functional-tests/501-writeback-details.py
+++ b/tests/functional-tests/501-writeback-details.py
@@ -21,10 +21,12 @@ from common.utils.writebacktest import CommonTrackerWritebackTest as CommonTrack
 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 +64,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 +77,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 = self.extractor.get_metadata (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..3701226 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"
@@ -89,6 +88,8 @@ class CommonTrackerWritebackTest (ut.TestCase):
         self.system = TrackerSystemAbstraction ()
 
         self.system.tracker_writeback_testing_start (CONF_OPTIONS)
+        log ("Waiting for miner to be idle")
+        self.system.tracker_miner_fs_wait_for_idle()
         # Returns when ready
         log ("Ready to go!")
         
@@ -106,3 +107,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]