Commit b93b6ec2 authored by Sam Thursfield's avatar Sam Thursfield

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.
parent 3eb4d289
......@@ -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"])
......
......@@ -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")
......
......@@ -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))
......
......@@ -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",
......
......@@ -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)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment