Commit a27e0148 authored by Sam Thursfield's avatar Sam Thursfield

functional-tests: Await resource addition / removal properly in 300, 310, 600

The tracker_miner_fs_wait_for_idle() function is not a good way to
detect when something has changed. We should always be listening
to GraphUpdated instead.

Thanks to Martin Kampas who did some of this already in commit
853eb94d.
parent 6d9481fc
......@@ -109,7 +109,8 @@ class MinerCrawlTest (CommonTrackerMinerTest):
source = os.path.join (MINER_TMP_DIR, "test-no-monitored", "file0.txt")
dest = os.path.join (MINER_TMP_DIR, "test-monitored", "file0.txt")
shutil.copyfile (source, dest)
self.system.tracker_miner_fs_wait_for_idle ()
dest_id, dest_urn = self.system.store.await_resource_inserted ('nfo:TextDocument', uri(dest))
# verify if miner indexed this file.
result = self.__get_text_documents ()
......@@ -123,7 +124,7 @@ class MinerCrawlTest (CommonTrackerMinerTest):
# Clean the new file so the test directory is as before
log ("Remove and wait")
os.remove (dest)
self.system.tracker_miner_fs_wait_for_idle ()
self.system.store.await_resource_deleted (dest_id)
def test_03_copy_from_monitored_to_unmonitored (self):
"""
......@@ -155,7 +156,8 @@ class MinerCrawlTest (CommonTrackerMinerTest):
source = os.path.join (MINER_TMP_DIR, "test-monitored", "file1.txt")
dest = os.path.join (MINER_TMP_DIR, "test-monitored", "dir1", "dir2", "file-test04.txt")
shutil.copyfile (source, dest)
self.system.tracker_miner_fs_wait_for_idle ()
dest_id, dest_urn = self.system.store.await_resource_inserted ('nfo:TextDocument', uri(dest))
result = self.__get_text_documents ()
self.assertEquals (len (result), 4)
......@@ -167,7 +169,7 @@ class MinerCrawlTest (CommonTrackerMinerTest):
# Clean the file
os.remove (dest)
self.system.tracker_miner_fs_wait_for_idle ()
self.system.store.await_resource_deleted (dest_id)
self.assertEquals (3, self.tracker.count_instances ("nfo:TextDocument"))
......@@ -178,7 +180,7 @@ class MinerCrawlTest (CommonTrackerMinerTest):
source = os.path.join (MINER_TMP_DIR, "test-no-monitored", "file0.txt")
dest = os.path.join (MINER_TMP_DIR, "test-monitored", "dir1", "file-test05.txt")
shutil.move (source, dest)
self.system.tracker_miner_fs_wait_for_idle ()
dest_id, dest_urn = self.system.store.await_resource_inserted ('nfo:TextDocument', uri(dest))
result = self.__get_text_documents ()
self.assertEquals (len (result), 4)
......@@ -190,7 +192,7 @@ class MinerCrawlTest (CommonTrackerMinerTest):
# Clean the file
os.remove (dest)
self.system.tracker_miner_fs_wait_for_idle ()
self.system.store.await_resource_deleted (dest_id)
self.assertEquals (3, self.tracker.count_instances ("nfo:TextDocument"))
## """ move operation and tracker-miner response test cases """
......@@ -203,8 +205,9 @@ class MinerCrawlTest (CommonTrackerMinerTest):
"""
source = os.path.join (MINER_TMP_DIR, "test-monitored", "dir1", "file2.txt")
dest = os.path.join (MINER_TMP_DIR, "test-no-monitored", "file2.txt")
source_id = self.system.store.get_resource_id (uri(dest))
shutil.move (source, dest)
self.system.tracker_miner_fs_wait_for_idle ()
self.system.store.await_resource_deleted (source_id)
result = self.__get_text_documents ()
self.assertEquals (len (result), 2)
......@@ -214,7 +217,7 @@ class MinerCrawlTest (CommonTrackerMinerTest):
# Restore the file
shutil.move (dest, source)
self.system.tracker_miner_fs_wait_for_idle ()
self.system.store.await_resource_inserted ('nfo:TextDocument', uri(dest))
self.assertEquals (3, self.tracker.count_instances ("nfo:TextDocument"))
......@@ -230,7 +233,7 @@ class MinerCrawlTest (CommonTrackerMinerTest):
self.assertEquals (source_dir_urn, parent_before)
shutil.move (source, dest)
self.system.tracker_miner_fs_wait_for_idle ()
self.system.store.await_resource_inserted ('nfo:TextDocument', uri(dest))
# Checking fix for NB#214413: After a move operation, nfo:belongsToContainer
# should be changed to the new one
......@@ -248,7 +251,7 @@ class MinerCrawlTest (CommonTrackerMinerTest):
# Restore the file
shutil.move (dest, source)
self.system.tracker_miner_fs_wait_for_idle ()
self.system.store.await_resource_inserted ('nfo:TextDocument', uri(source))
result = self.__get_text_documents ()
self.assertEquals (len (result), 3)
......@@ -261,8 +264,9 @@ class MinerCrawlTest (CommonTrackerMinerTest):
Delete one of the files
"""
victim = os.path.join (MINER_TMP_DIR, "test-monitored", "dir1", "file2.txt")
victim_id = self.system.store.get_resource_id (uri(victim))
os.remove (victim)
self.system.tracker_miner_fs_wait_for_idle ()
self.system.store.await_resource_deleted (victim_id)
result = self.__get_text_documents ()
self.assertEquals (len (result), 2)
......@@ -274,15 +278,16 @@ class MinerCrawlTest (CommonTrackerMinerTest):
f = open (victim, "w")
f.write ("Don't panic, everything is fine")
f.close ()
self.system.tracker_miner_fs_wait_for_idle ()
self.system.store.await_resource_inserted ('nfo:TextDocument', uri(victim))
def test_09_deletion_directory (self):
"""
Delete a directory
"""
victim = os.path.join (MINER_TMP_DIR, "test-monitored", "dir1")
victim_id = self.system.store.get_resource_id (uri(victim))
shutil.rmtree (victim)
self.system.tracker_miner_fs_wait_for_idle ()
self.system.store.await_resource_deleted (victim_id)
result = self.__get_text_documents ()
self.assertEquals (len (result), 1)
......@@ -301,10 +306,7 @@ class MinerCrawlTest (CommonTrackerMinerTest):
writer = open (filename, "w")
writer.write ("Don't panic, everything is fine")
writer.close ()
self.system.tracker_miner_fs_wait_for_idle ()
# Wait a bit more... some time one idle is not enough
self.system.tracker_miner_fs_wait_for_idle (3)
self.system.store.await_resource_inserted ('nfo:TextDocument', uri(f))
# Check everything is fine
result = self.__get_text_documents ()
......
......@@ -48,8 +48,7 @@ class CommonMinerFTS (CommonTrackerMinerTest):
os.remove (path (self.testfile))
self.tracker.await_resource_deleted (id)
self.tracker.reset_graph_updates_tracking ()
# Shouldn't we wait here for the miner to idle? (it works without it)
def tearDown (self):
#if os.path.exists (path (self.testfile)):
# os.remove (path (self.testfile))
......@@ -251,9 +250,6 @@ class MinerFTSFileOperationsTest (CommonMinerFTS):
Move file from unmonitored location to monitored location and index should be updated
"""
# Maybe the miner hasn't finished yet with the setUp deletion!
self.system.tracker_miner_fs_wait_for_idle ()
TEXT = "airplane is beautiful"
TEST_16_SOURCE = "test-no-monitored/fts-indexing-text-16.txt"
TEST_16_DEST = "test-monitored/fts-indexing-text-16.txt"
......
......@@ -85,13 +85,13 @@ class TrackerCameraPicturesApplicationTests (CommonTrackerApplicationTest):
# Copy the image to the dest path
self.slowcopy_file (origin_filepath, dest_filepath)
assert os.path.exists (dest_filepath)
self.system.tracker_miner_fs_wait_for_idle (MINER_FS_IDLE_TIMEOUT)
dest_id, dest_urn = self.system.store.await_resource_inserted ('nmm:Photo', dest_fileuri)
self.assertEquals (self.get_urn_count_by_url (dest_fileuri), 1)
# Clean the new file so the test directory is as before
log ("Remove and wait")
os.remove (dest_filepath)
self.system.tracker_miner_fs_wait_for_idle (MINER_FS_IDLE_TIMEOUT)
self.system.store.await_resource_deleted (dest_id)
self.assertEquals (self.get_urn_count_by_url (dest_fileuri), 0)
......@@ -171,13 +171,13 @@ class TrackerCameraPicturesApplicationTests (CommonTrackerApplicationTest):
assert os.path.exists (dest_filepath)
# FOURTH, ensure we have only 1 resource
self.system.tracker_miner_fs_wait_for_idle (MINER_FS_IDLE_TIMEOUT)
dest_id, dest_urn = self.system.store.await_resource_inserted ('nmm:Photo', dest_fileuri)
self.assertEquals (self.get_urn_count_by_url (dest_fileuri), 1)
# Clean the new file so the test directory is as before
log ("Remove and wait")
os.remove (dest_filepath)
self.system.tracker_miner_fs_wait_for_idle (MINER_FS_IDLE_TIMEOUT)
self.system.store.await_resource_deleted (dest_id)
self.assertEquals (self.get_urn_count_by_url (dest_fileuri), 0)
......@@ -228,13 +228,13 @@ class TrackerCameraVideosApplicationTests (CommonTrackerApplicationTest):
# Copy the image to the dest path
self.slowcopy_file (origin_filepath, dest_filepath)
assert os.path.exists (dest_filepath)
self.system.tracker_miner_fs_wait_for_idle (MINER_FS_IDLE_TIMEOUT)
dest_id, dest_urn = self.system.store.await_resource_inserted ('nmm:Video', dest_fileuri)
self.assertEquals (self.get_urn_count_by_url (dest_fileuri), 1)
# Clean the new file so the test directory is as before
log ("Remove and wait")
os.remove (dest_filepath)
self.system.tracker_miner_fs_wait_for_idle (MINER_FS_IDLE_TIMEOUT)
self.system.store.await_resource_deleted (dest_id)
self.assertEquals (self.get_urn_count_by_url (dest_fileuri), 0)
......@@ -314,13 +314,13 @@ class TrackerCameraVideosApplicationTests (CommonTrackerApplicationTest):
assert os.path.exists (dest_filepath)
# FOURTH, ensure we have only 1 resource
self.system.tracker_miner_fs_wait_for_idle (MINER_FS_IDLE_TIMEOUT)
dest_id, dest_urn = self.system.store.await_resource_inserted ('nmm:Video', dest_fileuri)
self.assertEquals (self.get_urn_count_by_url (dest_fileuri), 1)
# Clean the new file so the test directory is as before
log ("Remove and wait")
os.remove (dest_filepath)
self.system.tracker_miner_fs_wait_for_idle (MINER_FS_IDLE_TIMEOUT)
self.system.store.await_resource_deleted (dest_id)
self.assertEquals (self.get_urn_count_by_url (dest_fileuri), 0)
if __name__ == "__main__":
......
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