summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAndre Moreira Magalhaes <andre@endlessm.com>2019-07-22 20:21:06 -0300
committerAndre Moreira Magalhaes <andre@endlessm.com>2019-07-24 21:37:18 +0000
commit9a3ba4ed5c655cddcff0db15799600dcfa0431ba (patch)
tree06473fcab3bfa7eb5e310bcb0bbf74d64197de71 /tests
parentdcbdde9debcad50ec59596b74b4796c7acd650a3 (diff)
downloaddconf-9a3ba4ed5c655cddcff0db15799600dcfa0431ba.tar.gz
tests: Add new test to check GDBusConnection leaks
With recent changes made to GLib[1] invoking g_test_dbus_down() will fail after a timeout if the GDBusConnection object for the session bus leaks. Note that this new test will fail as the current code will leak a cached GDBusConnection. Fixes will be added in follow-up patches. [1] https://gitlab.gnome.org/GNOME/glib/merge_requests/963 Signed-off-by: Andre Moreira Magalhaes <andre@endlessm.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/dbus-leak.c45
-rw-r--r--tests/meson.build2
2 files changed, 47 insertions, 0 deletions
diff --git a/tests/dbus-leak.c b/tests/dbus-leak.c
new file mode 100644
index 0000000..f2a366b
--- /dev/null
+++ b/tests/dbus-leak.c
@@ -0,0 +1,45 @@
+#include "../engine/dconf-engine.h"
+
+static void
+test_engine_dbus_call (void)
+{
+ GError *error = NULL;
+ GVariant *reply;
+
+ /* Force a call to the engine to make sure at least one GDBusConnection
+ * is cached.
+ */
+ reply = dconf_engine_dbus_call_sync_func (G_BUS_TYPE_SESSION,
+ "org.freedesktop.DBus", "/", "org.freedesktop.DBus", "ListNames",
+ g_variant_new ("()"), G_VARIANT_TYPE ("(as)"), &error);
+ g_assert_no_error (error);
+ g_assert (reply != NULL);
+ g_assert (g_variant_is_of_type (reply, G_VARIANT_TYPE ("(as)")));
+ g_variant_unref (reply);
+}
+
+int
+main (int argc, char **argv)
+{
+ GTestDBus *test_bus;
+ int res;
+
+ g_test_init (&argc, &argv, NULL);
+
+ dconf_engine_dbus_init_for_testing ();
+
+ g_test_add_func (DBUS_BACKEND "/dbus/engine-dbus-call", test_engine_dbus_call);
+
+ test_bus = g_test_dbus_new (G_TEST_DBUS_NONE);
+
+ g_test_dbus_up (test_bus);
+
+ res = g_test_run ();
+
+ /* g_test_dbus_down will fail if GDBusConnection leaks */
+ g_test_dbus_down (test_bus);
+
+ g_object_unref (test_bus);
+
+ return res;
+}
diff --git a/tests/meson.build b/tests/meson.build
index 8aa5837..0d4260f 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -28,6 +28,8 @@ unit_tests = [
['gvdb', 'gvdb.c', '-DSRCDIR="@0@"'.format(test_dir), libgvdb_dep, []],
['gdbus-thread', 'dbus.c', '-DDBUS_BACKEND="/gdbus/thread"', libdconf_gdbus_thread_dep, []],
['gdbus-filter', 'dbus.c', '-DDBUS_BACKEND="/gdbus/filter"', libdconf_gdbus_filter_dep, []],
+ ['gdbus-thread-leak', 'dbus-leak.c', '-DDBUS_BACKEND="/gdbus/thread"', [libdconf_client_dep, libdconf_gdbus_thread_dep], []],
+ ['gdbus-filter-leak', 'dbus-leak.c', '-DDBUS_BACKEND="/gdbus/filter"', [libdconf_client_dep, libdconf_gdbus_filter_dep], []],
['engine', 'engine.c', '-DSRCDIR="@0@"'.format(test_dir), [dl_dep, libdconf_engine_test_dep, m_dep], libdconf_mock],
['client', 'client.c', '-DSRCDIR="@0@"'.format(test_dir), [libdconf_client_dep, libdconf_engine_dep], libdconf_mock],
['writer', 'writer.c', '-DSRCDIR="@0@"'.format(test_dir), [glib_dep, dl_dep, m_dep, libdconf_service_dep], [libdconf_mock]],