Commit fb5e4a81 authored by Sam Thursfield's avatar Sam Thursfield

functional-tests: Isolate 3xx-miner tests from each other

Rather than running all the tests in one environment, create a new
environment for each test. Although it's slower this way, it's just too
hard to debug test failures when the tests can interfere with each
other.

I also made them all use the same 'minertest' base class.
parent 12fe0ba6
......@@ -65,18 +65,6 @@ class MinerCrawlTest (CommonTrackerMinerTest):
self.assertEquals (len (result), 1)
return result[0][0]
def tearDown (self):
# Give it a 2 seconds chance
result = self.__get_text_documents ()
if (len (result) != 3):
time.sleep (2)
else:
return
result = self.__get_text_documents ()
if (len (result) != 3):
print "WARNING: Previous test has modified the test files and didn't restore the origina state."
"""
Boot the miner with the correct configuration and check everything is fine
"""
......
......@@ -52,42 +52,11 @@ CONF_OPTIONS = {
REASONABLE_TIMEOUT = 30
class MinerResourceRemovalTest (ut.TestCase):
# Use the same instances of store and miner-fs for the whole test suite,
# because they take so long to do first-time init.
@classmethod
def setUpClass (self):
log ("Using %s as temp dir\n" % MINER_TMP_DIR)
if os.path.exists (MINER_TMP_DIR):
shutil.rmtree (MINER_TMP_DIR)
os.makedirs (MINER_TMP_DIR)
self.system = TrackerSystemAbstraction ()
self.system.set_up_environment (CONF_OPTIONS, None)
self.store = StoreHelper ()
self.store.start ()
# GraphUpdated seems to not be emitted if the extractor isn't running
# even though the file resource still gets inserted - maybe because
# INSERT SILENT is used in the FS miner?
self.extractor = ExtractorHelper ()
self.extractor.start ()
self.miner_fs = MinerFsHelper ()
self.miner_fs.start ()
@classmethod
def tearDownClass (self):
self.miner_fs.stop ()
self.extractor.stop ()
self.store.stop ()
def setUp (self):
self.store.reset_graph_updates_tracking ()
def tearDown (self):
self.system.unset_up_environment ()
class MinerResourceRemovalTest (CommonTrackerMinerTest):
def prepare_directories (self):
# Override content from the base class
pass
def create_test_content (self, file_urn, title):
sparql = "INSERT { \
......@@ -96,10 +65,10 @@ class MinerResourceRemovalTest (ut.TestCase):
nie:isStoredAs <%s> \
} " % (title, file_urn)
self.store.update (sparql)
self.tracker.update (sparql)
return self.store.await_resource_inserted (rdf_class = 'nmm:MusicPiece',
title = title)
return self.tracker.await_resource_inserted (rdf_class = 'nmm:MusicPiece',
title = title)
def create_test_file (self, file_name):
file_path = path(file_name)
......@@ -108,15 +77,15 @@ class MinerResourceRemovalTest (ut.TestCase):
file.write ("Test")
file.close ()
return self.store.await_resource_inserted (rdf_class = 'nfo:Document',
url = uri(file_name))
return self.tracker.await_resource_inserted (rdf_class = 'nfo:Document',
url = uri(file_name))
def assertResourceExists (self, urn):
if self.store.ask ("ASK { <%s> a rdfs:Resource }" % urn) == False:
if self.tracker.ask ("ASK { <%s> a rdfs:Resource }" % urn) == False:
self.fail ("Resource <%s> does not exist" % urn)
def assertResourceMissing (self, urn):
if self.store.ask ("ASK { <%s> a rdfs:Resource }" % urn) == True:
if self.tracker.ask ("ASK { <%s> a rdfs:Resource }" % urn) == True:
self.fail ("Resource <%s> should not exist" % urn)
......@@ -133,10 +102,10 @@ class MinerResourceRemovalTest (ut.TestCase):
os.unlink (path ("test-monitored/test_1.txt"))
self.store.await_resource_deleted (file_1_id)
self.store.await_resource_deleted (ie_1_id,
"Associated logical resource failed to be deleted " \
"when its containing file was removed.")
self.tracker.await_resource_deleted (file_1_id)
self.tracker.await_resource_deleted (ie_1_id,
"Associated logical resource failed to be deleted " \
"when its containing file was removed.")
self.assertResourceMissing (file_1_urn)
self.assertResourceMissing (ie_1_urn)
......
......@@ -40,19 +40,16 @@ class CommonMinerFTS (CommonTrackerMinerTest):
"""
Superclass to share methods. Shouldn't be run by itself.
"""
def prepare_directories (self):
# Override content from the base class
pass
def setUp (self):
self.tracker.reset_graph_updates_tracking ()
self.testfile = "test-monitored/miner-fts-test.txt"
if os.path.exists (path (self.testfile)):
id = self._query_id (uri (self.testfile))
os.remove (path (self.testfile))
self.tracker.await_resource_deleted (id)
self.tracker.reset_graph_updates_tracking ()
def tearDown (self):
#if os.path.exists (path (self.testfile)):
# os.remove (path (self.testfile))
pass
super(CommonMinerFTS, self).setUp()
def set_text (self, text):
exists = os.path.exists(path(self.testfile))
......
......@@ -53,8 +53,7 @@ CONF_OPTIONS = {
class CommonTrackerMinerTest (ut.TestCase):
@classmethod
def __prepare_directories (self):
def prepare_directories (self):
#
# ~/test-monitored/
# /file1.txt
......@@ -92,8 +91,7 @@ class CommonTrackerMinerTest (ut.TestCase):
self.tracker.await_resource_inserted(
'nfo:TextDocument', url=uri(tf))
@classmethod
def setUpClass (self):
def setUp (self):
for d in ['test-monitored', 'test-no-monitored']:
dirname = path(d)
if os.path.exists (dirname):
......@@ -105,11 +103,12 @@ class CommonTrackerMinerTest (ut.TestCase):
self.system.tracker_miner_fs_testing_start (CONF_OPTIONS)
self.tracker = self.system.store
self.__prepare_directories ()
try:
self.prepare_directories ()
self.tracker.reset_graph_updates_tracking ()
except Exception as e:
self.tearDown ()
raise
@classmethod
def tearDownClass (self):
def tearDown (self):
self.system.tracker_miner_fs_testing_stop ()
def setUp (self):
self.tracker.reset_graph_updates_tracking ()
......@@ -78,28 +78,11 @@ class TrackerSystemAbstraction:
for key, value in contents.iteritems():
dconf.write(key, value)
def unset_up_environment (self):
"""
Unset the XDG_*_HOME variables from the environment
"""
for var, directory in TEST_ENV_VARS.iteritems ():
if os.environ.has_key (var):
del os.environ [var]
for var, directory in TEST_ENV_DIRS.iteritems ():
if os.environ.has_key (var):
del os.environ [var]
if (os.environ.has_key ("TRACKER_DB_ONTOLOGIES_DIR")):
del os.environ ["TRACKER_DB_ONTOLOGIES_DIR"]
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.__stop_tracker_processes ()
self.set_up_environment (confdir, ontodir)
self.store = helpers.StoreHelper ()
......@@ -153,11 +136,10 @@ class TrackerSystemAbstraction:
def tracker_store_testing_stop (self):
"""
Stops a running tracker-store and unset all the XDG_*_HOME vars
Stops a running tracker-store
"""
assert self.store
self.store.stop ()
self.unset_up_environment ()
def tracker_miner_fs_testing_start (self, confdir=None):
......@@ -165,7 +147,6 @@ class TrackerSystemAbstraction:
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.__stop_tracker_processes ()
self.set_up_environment (confdir, None)
# Start also the store. DBus autoactivation ignores the env variables.
......@@ -180,15 +161,12 @@ class TrackerSystemAbstraction:
def tracker_miner_fs_testing_stop (self):
"""
Stops the miner-fs and store running and unset all the XDG_*_HOME vars
Stops the extractor, miner-fs and store running
"""
self.extractor.stop ()
self.miner_fs.stop ()
self.store.stop ()
self.__stop_tracker_processes ()
self.unset_up_environment ()
def tracker_writeback_testing_start (self, confdir=None):
# Start the miner-fs (and store) and then the writeback process
self.tracker_miner_fs_testing_start (confdir)
......@@ -208,15 +186,6 @@ class TrackerSystemAbstraction:
# This will stop all miner-fs, store and writeback
self.tracker_writeback_testing_stop ()
#
# Private API
#
def __stop_tracker_processes (self):
control_binary = os.path.join (cfg.BINDIR, "tracker")
FNULL = open('/dev/null', 'w')
subprocess.call ([control_binary, "daemon", "-t"], stdout=FNULL)
time.sleep (1)
def __recreate_directory (self, directory):
if (os.path.exists (directory)):
shutil.rmtree (directory)
......
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