[tracker/sam/functional-test-fixes: 4/30] functional-tests: Await resource addition / removal properly



commit 731013edb715b30bf7243c2a0aabbc492d54178e
Author: Sam Thursfield <sam afuera me uk>
Date:   Sun Jul 20 15:36:14 2014 +0100

    functional-tests: Await resource addition / removal properly
    
    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
    853eb94d78aa269b3b1024c138387ead0c601080.

 tests/functional-tests/300-miner-basic-ops.py     |   38 +++++++++++----------
 tests/functional-tests/310-fts-indexing.py        |    6 +---
 tests/functional-tests/600-applications-camera.py |   16 ++++----
 tests/functional-tests/common/utils/helpers.py    |    8 ++++
 4 files changed, 37 insertions(+), 31 deletions(-)
---
diff --git a/tests/functional-tests/300-miner-basic-ops.py b/tests/functional-tests/300-miner-basic-ops.py
index c887560..124e992 100755
--- a/tests/functional-tests/300-miner-basic-ops.py
+++ b/tests/functional-tests/300-miner-basic-ops.py
@@ -30,7 +30,7 @@ import shutil
 import time
 
 import unittest2 as ut
-from common.utils.helpers import log
+from common.utils.helpers import log, path_to_url
 from common.utils.minertest import CommonTrackerMinerTest, MINER_TMP_DIR, uri, path
 
 class MinerCrawlTest (CommonTrackerMinerTest):
@@ -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', path_to_url(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', path_to_url(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', path_to_url(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 (path_to_url(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', path_to_url(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', path_to_url(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', path_to_url(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 (path_to_url(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', path_to_url(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 (path_to_url(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 ()
diff --git a/tests/functional-tests/310-fts-indexing.py b/tests/functional-tests/310-fts-indexing.py
index 99db45d..90e0c7d 100755
--- a/tests/functional-tests/310-fts-indexing.py
+++ b/tests/functional-tests/310-fts-indexing.py
@@ -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"
diff --git a/tests/functional-tests/600-applications-camera.py 
b/tests/functional-tests/600-applications-camera.py
index 126ebd7..f793665 100755
--- a/tests/functional-tests/600-applications-camera.py
+++ b/tests/functional-tests/600-applications-camera.py
@@ -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__":
diff --git a/tests/functional-tests/common/utils/helpers.py b/tests/functional-tests/common/utils/helpers.py
index 897db98..91f4de3 100644
--- a/tests/functional-tests/common/utils/helpers.py
+++ b/tests/functional-tests/common/utils/helpers.py
@@ -26,6 +26,8 @@ import subprocess
 import time
 from dbus.mainloop.glib import DBusGMainLoop
 import re
+import urllib
+import urlparse
 
 import configuration as cfg
 import options
@@ -39,6 +41,12 @@ def log (message):
     if options.is_verbose ():
         print (message)
 
+
+def path_to_url (path):
+    encoded_path = urllib.pathname2url(path)
+    return urlparse.urljoin('file:', encoded_path)
+
+
 class Helper:
     """
     Abstract helper for Tracker processes. Launches the process manually


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