[tracker/wip/carlosg/deserializer-cursors: 14/15] tests: Test both JSON and XML cursors




commit b84baa135e27478372a16dbecea22d04d31c84db
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sun May 1 17:51:17 2022 +0200

    tests: Test both JSON and XML cursors
    
    There is no exposed mechanism to decide what cursor format do
    an endpoint/cursor negotiate between themselves, as a result
    we are currently only testing the JSON cursor format.
    
    Add a test-only environment variable so that TrackerEndpointHttp
    prefers a given TrackerSerializerFormat, and run cursor tests
    twice to ensure we test all cursor paths on HTTP connections.
    
    This additionally also exercises the XML serializer on the HTTP
    endpoint side.

 src/libtracker-sparql/tracker-endpoint-http.c | 11 +++++++++++
 tests/libtracker-sparql/meson.build           | 10 +++++++++-
 tests/libtracker-sparql/tracker-cursor-test.c | 12 ++++++++++--
 tests/meson.build                             | 13 +++++++++----
 4 files changed, 39 insertions(+), 7 deletions(-)
---
diff --git a/src/libtracker-sparql/tracker-endpoint-http.c b/src/libtracker-sparql/tracker-endpoint-http.c
index 60f308793..00395a690 100644
--- a/src/libtracker-sparql/tracker-endpoint-http.c
+++ b/src/libtracker-sparql/tracker-endpoint-http.c
@@ -138,6 +138,17 @@ pick_format (guint                    formats,
              TrackerSerializerFormat *format)
 {
        TrackerSerializerFormat i;
+       const gchar *test_format;
+
+       test_format = g_getenv ("TRACKER_TEST_PREFERRED_CURSOR_FORMAT");
+       if (test_format && g_ascii_isdigit (*test_format)) {
+               int f = atoi (test_format);
+
+               if ((formats & (1 << f)) != 0) {
+                       *format = f;
+                       return TRUE;
+               }
+       }
 
        for (i = 0; i < TRACKER_N_SERIALIZER_FORMATS; i++) {
                if ((formats & (1 << i)) != 0) {
diff --git a/tests/libtracker-sparql/meson.build b/tests/libtracker-sparql/meson.build
index c3e1e097c..a7cf6c3ae 100644
--- a/tests/libtracker-sparql/meson.build
+++ b/tests/libtracker-sparql/meson.build
@@ -47,9 +47,17 @@ tracker_cursor_test = executable('tracker-cursor-test',
   c_args: libtracker_sparql_test_c_args)
 
 tests += {
-  'name': 'cursor',
+  'name': 'cursor+json',
   'exe': tracker_cursor_test,
   'suite': ['sparql'],
+  'env': { 'TRACKER_TEST_PREFERRED_CURSOR_FORMAT': '0' },
+}
+
+tests += {
+  'name': 'cursor+xml',
+  'exe': tracker_cursor_test,
+  'suite': ['sparql'],
+  'env': { 'TRACKER_TEST_PREFERRED_CURSOR_FORMAT': '1' },
 }
 
 test_gresources = gnome.compile_resources('test_gresources', 'statement-queries.gresource.xml')
diff --git a/tests/libtracker-sparql/tracker-cursor-test.c b/tests/libtracker-sparql/tracker-cursor-test.c
index 994424bc6..38fa701e6 100644
--- a/tests/libtracker-sparql/tracker-cursor-test.c
+++ b/tests/libtracker-sparql/tracker-cursor-test.c
@@ -33,6 +33,8 @@ typedef struct {
        const gchar *query;
 } AsyncData;
 
+static int http_port;
+
 static TrackerSparqlConnection *direct;
 static TrackerSparqlConnection *dbus;
 static TrackerSparqlConnection *http;
@@ -375,7 +377,7 @@ thread_func (gpointer user_data)
        endpoint_bus = tracker_endpoint_dbus_new (direct, dbus_conn, NULL, NULL, &error);
        g_assert_no_error (error);
 
-       endpoint_http = tracker_endpoint_http_new (direct, 54320, NULL, NULL, &error);
+       endpoint_http = tracker_endpoint_http_new (direct, http_port, NULL, NULL, &error);
        g_assert_no_error (error);
 
        started = TRUE;
@@ -390,6 +392,9 @@ create_connections (void)
        GDBusConnection *dbus_conn;
        GThread *thread;
        GError *error = NULL;
+       gchar *host;
+
+       http_port = g_test_rand_int_range (30000, 60000);
 
        dbus_conn = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
        g_assert_no_error (error);
@@ -399,7 +404,10 @@ create_connections (void)
        while (!started)
                g_usleep (100);
 
-       http = tracker_sparql_connection_remote_new ("http://127.0.0.1:54320/sparql";);
+       host = g_strdup_printf ("http://127.0.0.1:%d/sparql";, http_port);
+       http = tracker_sparql_connection_remote_new (host);
+       g_free (host);
+
        dbus = tracker_sparql_connection_bus_new (g_dbus_connection_get_unique_name (dbus_conn),
                                                  NULL, dbus_conn, &error);
        g_assert_no_error (error);
diff --git a/tests/meson.build b/tests/meson.build
index 2bfb58d28..3b39382f6 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -26,17 +26,22 @@ foreach t: tests
   test_exe = t.get('exe')
   test_suite = t.get('suite', [])
   test_timeout = t.get('timeout', 30)
+  test_env = t.get('env', {})
 
   # 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)
 
-  test_env = environment()
-  test_env.set('TRACKER_LANGUAGE_STOP_WORDS_DIR', join_paths(source_root, 'src', 'libtracker-common', 
'stop-words'))
-  test_env.set('LANG', 'en_US.UTF8')
+  env = environment()
+  env.set('TRACKER_LANGUAGE_STOP_WORDS_DIR', join_paths(source_root, 'src', 'libtracker-common', 
'stop-words'))
+  env.set('LANG', 'en_US.UTF8')
+
+  foreach envvar_name, envvar_val: test_env
+    env.set(envvar_name, envvar_val)
+  endforeach
 
   test(test_name, test_exe,
-    env: test_env,
+    env: env,
     timeout: test_timeout,
     protocol: protocol,
     suite: test_suite,


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