[tracker/wip/sam/meson-functional-tests: 59/60] functional-tests: Fix tests that depend on generated .ttl files



commit 9c7925428aeda3bf3a89a8a13c0fef6e7a8d0471
Author: Sam Thursfield <sam thursfield codethink co uk>
Date:   Wed Nov 1 18:05:50 2017 +0000

    functional-tests: Fix tests that depend on generated .ttl files
    
    These now execute as expected. Not all of them actually work though.

 tests/functional-tests/10-sqlite-misused.py        |   27 ++++++++++--------
 tests/functional-tests/11-sqlite-batch-misused.py  |   27 +++++++++--------
 tests/functional-tests/13-threaded-store.py        |    4 +-
 .../common/utils/configuration.py.in               |    9 ++++++
 tests/functional-tests/common/utils/helpers.py     |    3 ++
 tests/functional-tests/meson.build                 |   30 +++++++++++++++++--
 6 files changed, 69 insertions(+), 31 deletions(-)
---
diff --git a/tests/functional-tests/10-sqlite-misused.py b/tests/functional-tests/10-sqlite-misused.py
index e9203e3..0b7dc9d 100755
--- a/tests/functional-tests/10-sqlite-misused.py
+++ b/tests/functional-tests/10-sqlite-misused.py
@@ -36,20 +36,24 @@ class TestSqliteMisused (CommonTrackerStoreTest):
     def setUp (self):
         self.main_loop = GObject.MainLoop ()
         self.files_counter = 0
-        
+
     def test_queries_while_import (self):
-        self.assertTrue (os.path.exists ('ttl'))
-        for root, dirs, files in os.walk('ttl'):
+        assert os.path.isdir(cfg.generated_ttl_dir())
+
+        for root, dirs, files in os.walk(cfg.generated_ttl_dir()):
             for ttl_file in filter (lambda f: f.endswith (".ttl"), files):
                 full_path = os.path.abspath(os.path.join (root, ttl_file))
                 self.files_counter += 1
-                self.tracker.query(
+
+                self.tracker.load(
                     "file://" + full_path, timeout=30000,
                     result_handler=self.loaded_success_cb,
-                    error_handler=self.loaded_failed_cb)
+                    error_handler=self.loaded_failed_cb,
+                    user_data = full_path)
 
         GObject.timeout_add_seconds (2, self.run_a_query)
         # Safeguard of 60 seconds. The last reply should quit the loop
+        # It doesn't matter if we didn't import all of the files yet.
         GObject.timeout_add_seconds (60, self.timeout_cb)
         self.main_loop.run ()
 
@@ -64,19 +68,18 @@ class TestSqliteMisused (CommonTrackerStoreTest):
     def reply_cb (self, obj, results, data):
         print "Query replied correctly"
 
-    def error_handler (self, error_msg):
-        print "ERROR in DBus call", error_msg
+    def error_handler (self, obj, error, data):
+        print "ERROR in DBus call: %s" % error
 
-    def loaded_success_cb (self, obj, results, data):
+    def loaded_success_cb (self, obj, results, user_data):
         self.files_counter -= 1
         if (self.files_counter == 0):
             print "Last file loaded"
             self.timeout_cb ()
-        print "Success loading a file"
+        print "Success loading %s" % user_data
 
-    def loaded_failed_cb (self, error):
-        print "Failed loading a file"
-        self.assertTrue (False)
+    def loaded_failed_cb (self, obj, error, user_data):
+        raise RuntimeError("Failed loading %s: %s" % (user_data, error))
 
     def timeout_cb (self):
         print "Forced timeout after 60 sec."
diff --git a/tests/functional-tests/11-sqlite-batch-misused.py 
b/tests/functional-tests/11-sqlite-batch-misused.py
index c4ef0be..cc810f2 100755
--- a/tests/functional-tests/11-sqlite-batch-misused.py
+++ b/tests/functional-tests/11-sqlite-batch-misused.py
@@ -41,11 +41,11 @@ class TestSqliteBatchMisused (CommonTrackerStoreTest):
     def setUp (self):
         self.main_loop = GObject.MainLoop ()
         self.batch_counter = 0
-        
+
     def test_queries_while_batch_insert (self):
-        self.assertTrue (os.path.exists ('ttl'))
-        
-        for root, dirs, files in os.walk('ttl'):
+        self.assertTrue (os.path.exists (cfg.generated_ttl_dir()))
+
+        for root, dirs, files in os.walk(cfg.generated_ttl_dir()):
             for ttl_file in filter (lambda f: f.endswith (".ttl"), files):
                 full_path = os.path.abspath(os.path.join (root, ttl_file))
                 print full_path
@@ -58,10 +58,10 @@ class TestSqliteBatchMisused (CommonTrackerStoreTest):
                     current_batch += line
                     if len(line) > 1 and line[:-1].endswith ('.'):
                         counter += 1
-                
-                    if counter == BATCH_SIZE:
+
+                    if counter >= BATCH_SIZE:
                         query = "INSERT {" + current_batch + "}"
-                        self.tracker.batch_update(
+                        token = self.tracker.batch_update(
                             query,
                             timeout=20000,
                             result_handler=self.batch_success_cb,
@@ -70,8 +70,7 @@ class TestSqliteBatchMisused (CommonTrackerStoreTest):
                         counter = 0
                         current_batch = ""
                         self.batch_counter += 1
-                        
-        
+
         GObject.timeout_add_seconds (2, self.run_a_query)
         # Safeguard of 60 seconds. The last reply should quit the loop
         GObject.timeout_add_seconds (60, self.timeout_cb)
@@ -84,22 +83,24 @@ class TestSqliteBatchMisused (CommonTrackerStoreTest):
             reply_handler=self.reply_cb,
             error_handler=self.error_handler)
         return True
-        
+
     def reply_cb (self, obj, results, data):
         print "Query replied correctly"
 
     def error_handler (self, error_msg):
         print "Query failed", error_msg
+        raise error_msg
 
-    def batch_success_cb (self):
+    def batch_success_cb (self, obj, result, user_data):
         self.batch_counter -= 1
         if (self.batch_counter == 0):
             print "Last batch was success"
             self.timeout_cb ()
         print "Success processing a batch"
 
-    def batch_failed_cb (self, error):
-        print "Failed processing a batch"
+    def batch_failed_cb (self, obj, error, user_data):
+        print "Failed processing a batch: %s" % error
+        raise error
 
     def timeout_cb (self):
         print "Forced timeout after 60 sec."
diff --git a/tests/functional-tests/13-threaded-store.py b/tests/functional-tests/13-threaded-store.py
index 55d76c1..d24da78 100755
--- a/tests/functional-tests/13-threaded-store.py
+++ b/tests/functional-tests/13-threaded-store.py
@@ -52,7 +52,7 @@ class TestThreadedStore (CommonTrackerStoreTest):
 
     def __populate_database (self):
 
-        self.assertTrue (os.path.exists ('ttl'))
+        self.assertTrue (os.path.exists (cfg.generated_ttl_dir()))
         for ttl_file in ["010-nco_EmailAddress.ttl",
                          "011-nco_PostalAddress.ttl",
                          "012-nco_PhoneNumber.ttl",
@@ -61,7 +61,7 @@ class TestThreadedStore (CommonTrackerStoreTest):
                          "018-nco_PersonContact.ttl",
                          "012-nco_PhoneNumber.ttl",
                          "016-nco_ContactIM.ttl"]:
-            full_path = os.path.abspath(os.path.join ("ttl", ttl_file))
+            full_path = os.path.abspath(os.path.join (cfg.generated_ttl_dir(), ttl_file))
             print full_path
             self.tracker.get_tracker_iface().Load(
                 '(s)', "file://" + full_path, timeout=30000)
diff --git a/tests/functional-tests/common/utils/configuration.py.in 
b/tests/functional-tests/common/utils/configuration.py.in
index 6bc3b1b..bc4b114 100644
--- a/tests/functional-tests/common/utils/configuration.py.in
+++ b/tests/functional-tests/common/utils/configuration.py.in
@@ -92,3 +92,12 @@ if TEST_TMP_DIR.startswith('/tmp'):
                print ("HOME is in the /tmp prefix - this will cause tests that rely " +
                       "on filesystem monitoring to fail as changes in that prefix are " +
                       "ignored.")
+
+
+BUILD_DIR = os.environ.get('TRACKER_FUNCTIONAL_TEST_BUILD_DIR')
+
+def generated_ttl_dir():
+    if BUILD_DIR:
+        return os.path.join(BUILD_DIR, 'tests', 'functional-tests', 'ttl')
+    else:
+        return 'ttl'
diff --git a/tests/functional-tests/common/utils/helpers.py b/tests/functional-tests/common/utils/helpers.py
index d085e26..66debbd 100644
--- a/tests/functional-tests/common/utils/helpers.py
+++ b/tests/functional-tests/common/utils/helpers.py
@@ -469,6 +469,9 @@ class StoreHelper (Helper):
     def update (self, update_sparql, timeout=5000, **kwargs):
         return self.resources.SparqlUpdate ('(s)', update_sparql, timeout=timeout, **kwargs)
 
+    def load (self, ttl_uri, timeout=5000, **kwargs):
+        return self.resources.Load ('(s)', ttl_uri, timeout=timeout, **kwargs)
+
     def batch_update (self, update_sparql, **kwargs):
         return self.resources.BatchSparqlUpdate ('(s)', update_sparql, **kwargs)
 
diff --git a/tests/functional-tests/meson.build b/tests/functional-tests/meson.build
index 8261e14..7998f73 100644
--- a/tests/functional-tests/meson.build
+++ b/tests/functional-tests/meson.build
@@ -2,6 +2,12 @@ subdir('ipc')
 
 test_runner = find_program('test-runner.sh')
 
+config_json = configure_file(
+  input: 'configuration.json.in',
+  output: 'configuration.json',
+  configuration: conf
+)
+
 functional_tests = [
   '01-insertion',
   '02-sparql-bugs',
@@ -12,10 +18,7 @@ functional_tests = [
   '07-graph',
   '08-unique-insertions',
   '09-concurrent-query',
-  '10-sqlite-misused',
-  '11-sqlite-batch-misused',
   '12-transactions',
-  '13-threaded-store',
   '14-signals',
   '15-statistics',
   '16-collation',
@@ -23,9 +26,28 @@ functional_tests = [
   '200-backup-restore',
 ]
 
-foreach t: functional_tests
+subdir('ttl')
+functional_tests_with_test_data = [
+  '10-sqlite-misused',
+  '11-sqlite-batch-misused',
+  '13-threaded-store',
+]
+
+tracker_top_build_dir = join_paths(meson.current_build_dir(), '..', '..')
+
+dconf_profile_full_path = join_paths(meson.current_source_dir(), 'trackertest')
+config_json_full_path = join_paths(meson.current_build_dir(), 'configuration.json')
+
+test_env = environment()
+test_env.set('DCONF_PROFILE', dconf_profile_full_path)
+test_env.set('TRACKER_FUNCTIONAL_TEST_CONFIG', config_json_full_path)
+test_env.set('TRACKER_DB_ONTOLOGIES_DIR', tracker_nepomuk_ontologies)
+test_env.set('TRACKER_TEST_DOMAIN_ONTOLOGY_RULE', tracker_test_domain_ontology)
+
+foreach t: functional_tests + functional_tests_with_test_data
   test('functional-' + t, test_runner,
     args: './' + t + '.py',
+    env: test_env,
     workdir: meson.current_source_dir(),
     # FIXME: these tests are all too slow
     timeout: 180)


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