[tracker/sam/tracker-test-dbus-services: 2/2] tests: Explicitly mark the unit tests which require D-Bus



commit 9ed10b1e9d3921528edc8d576b04b7c85f94aa6b
Author: Sam Thursfield <sam afuera me uk>
Date:   Sat May 25 20:50:48 2019 +0200

    tests: Explicitly mark the unit tests which require D-Bus
    
    The unit tests should in theory never talk to D-Bus. In practice,
    some don't follow this rule. We now run these tests in a separate
    D-Bus session so that they are correctly isolated from the host,
    which is nice, but eventually we should either move such tests into
    the functional-tests suite, or modify them so that they don't need
    to spawn and communicate with external processes.

 tests/libtracker-data/meson.build   |  4 +++-
 tests/libtracker-fts/meson.build    |  3 ++-
 tests/libtracker-sparql/meson.build | 38 ++++++++++++++++++-------------------
 tests/meson.build                   | 29 +++++++++++++++++++++-------
 tests/tracker-steroids/meson.build  |  3 ++-
 5 files changed, 48 insertions(+), 29 deletions(-)
---
diff --git a/tests/libtracker-data/meson.build b/tests/libtracker-data/meson.build
index fcbe8c091..dd559ccd7 100644
--- a/tests/libtracker-data/meson.build
+++ b/tests/libtracker-data/meson.build
@@ -24,7 +24,8 @@ foreach base_name: libtracker_data_tests
 
     tests += {
       'name': test_name,
-      'exe': binary
+      'exe': binary,
+      'requires_dbus': true,
     }
 endforeach
 
@@ -40,6 +41,7 @@ foreach base_name: libtracker_data_slow_tests
       tests += {
         'name': test_name,
         'exe': binary,
+        'requires_dbus': true,
         'timeout': 180
     }
 endforeach
diff --git a/tests/libtracker-fts/meson.build b/tests/libtracker-fts/meson.build
index e851d7abe..7de35649b 100644
--- a/tests/libtracker-fts/meson.build
+++ b/tests/libtracker-fts/meson.build
@@ -6,5 +6,6 @@ fts_test = executable('tracker-fts-test',
 
 tests += {
   'name': 'fts',
-  'exe': fts_test
+  'exe': fts_test,
+  'requires_dbus': true,
 }
diff --git a/tests/libtracker-sparql/meson.build b/tests/libtracker-sparql/meson.build
index 6c742d8d4..7dc9e9813 100644
--- a/tests/libtracker-sparql/meson.build
+++ b/tests/libtracker-sparql/meson.build
@@ -1,8 +1,3 @@
-libtracker_sparql_tests = [
-    'resource',
-    'sparql',
-]
-
 libtracker_sparql_test_c_args = tracker_c_args + [
   '-DTEST',
   '-DTEST_DOMAIN_ONTOLOGY_RULE="@0@"'.format(tracker_uninstalled_domain_rule),
@@ -13,19 +8,24 @@ libtracker_sparql_test_deps = [
     tracker_common_dep, tracker_sparql_dep
 ]
 
-foreach base_name: libtracker_sparql_tests
-    source = 'tracker-@0@-test.c'.format(base_name)
-    binary_name = 'tracker-@0@-test'.format(base_name)
-    test_name = 'sparql-@0@'.format(base_name)
+tracker_resource_test = executable('tracker-resource-test',
+  'tracker-resource-test.c',
+  dependencies: libtracker_sparql_test_deps,
+  c_args: libtracker_sparql_test_c_args)
+
+tests += {
+  'name': 'tracker-resource-test',
+  'exe': tracker_resource_test,
+}
 
-    binary = executable(binary_name, source,
-      dependencies: libtracker_sparql_test_deps,
-      c_args: libtracker_sparql_test_c_args)
+tracker_sparql_test = executable('tracker-sparql-test',
+  'tracker-sparql-test.c',
+  dependencies: libtracker_sparql_test_deps,
+  c_args: libtracker_sparql_test_c_args)
 
-    tests += {
-      'name': test_name,
-      'exe': binary,
-      'is_parallel': false
-    }
-    [[test_name, binary]]
-endforeach
+tests += {
+  'name': 'tracker-sparql-test',
+  'exe': tracker_sparql_test,
+  'is_parallel': false,
+  'requires_dbus': true,
+}
diff --git a/tests/meson.build b/tests/meson.build
index 85f4bc333..2e19b0623 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -29,8 +29,16 @@ foreach t: tests
   test_name = t.get('name')
   test_exe = t.get('exe')
   test_timeout = t.get('timeout', 30)
+
+  # This flag marks unit tests which can't run alongside other unit tests. It
+  # generally indicates a bug or design flaw in that test.
   test_is_parallel = t.get('is_parallel', true)
 
+  # This flag marks unit tests which need to contact a D-Bus session bus. This
+  # is a sign of a bad unit test -- anything which uses D-Bus belongs in the
+  # functional-tests directory.
+  test_requires_dbus = t.get('requires_dbus', false)
+
   test_env = environment()
   test_env.set('GSETTINGS_SCHEMA_DIR', join_paths(build_root, 'data'))
   test_env.set('TRACKER_LANGUAGE_STOP_WORDS_DIR', join_paths(source_root, 'src', 'libtracker-common', 
'stop-words'))
@@ -38,11 +46,18 @@ foreach t: tests
   test_env.set('TRACKER_DB_ONTOLOGIES_DIR', join_paths(source_root, 'src', 'ontologies', 'nepomuk'))
   test_env.set('LANG', 'en_US.UTF8')
 
-  test (test_name, dbus_run_session,
-    env: test_env,
-    args: ['--config-file=@0@'.format(join_paths(meson.current_build_dir(), 'test-bus.conf')),
-           '--',
-           test_exe],
-    timeout: test_timeout,
-    is_parallel: test_is_parallel)
+  if test_requires_dbus
+    test (test_name, dbus_run_session,
+      env: test_env,
+      args: ['--config-file=@0@'.format(join_paths(meson.current_build_dir(), 'test-bus.conf')),
+             '--',
+             test_exe],
+      timeout: test_timeout,
+      is_parallel: test_is_parallel)
+  else
+    test (test_name, test_exe,
+          env: test_env,
+          timeout: test_timeout,
+          is_parallel: test_is_parallel)
+  endif
 endforeach
diff --git a/tests/tracker-steroids/meson.build b/tests/tracker-steroids/meson.build
index 79ae8bf30..a9dff2d11 100644
--- a/tests/tracker-steroids/meson.build
+++ b/tests/tracker-steroids/meson.build
@@ -9,5 +9,6 @@ steroids_test = executable('tracker-steroids-test',
   c_args: [tracker_c_args, test_c_args])
 tests += {
   'name': 'steroids',
-  'exe': steroids_test
+  'exe': steroids_test,
+  'requires_dbus': true,
 }


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