From 1a35d27f1b3c2bec568ecfc9b54d863318e9893b Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 5 May 2020 15:02:07 +0100 Subject: [PATCH] tests: Isolate directory access for gdbus-server-auth test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When multiple tests were run in parallel, this would race on its access to `~/.dbus-keyrings` to authenticate with the D-Bus server, since the keyring directory was not appropriately sandboxed to the unit test. Use `G_TEST_OPTION_ISOLATE_DIRS` to automatically isolate each unit test’s directory usage. Signed-off-by: Philip Withnall Fixes: #1954 --- gio/tests/gdbus-server-auth.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/gio/tests/gdbus-server-auth.c b/gio/tests/gdbus-server-auth.c index e782bd3d7..2554ad6ab 100644 --- a/gio/tests/gdbus-server-auth.c +++ b/gio/tests/gdbus-server-auth.c @@ -398,6 +398,14 @@ do_test_server_auth (InteropFlags flags) LibdbusCall libdbus_call = { DBUS_ERROR_INIT, NULL, NULL, NULL }; GTask *task; + /* The test suite uses %G_TEST_OPTION_ISOLATE_DIRS, which sets + * `HOME=/dev/null` and leaves g_get_home_dir() pointing to the per-test + * temp home directory. Unfortunately, libdbus doesn’t allow the home dir + * to be overridden except using the environment, so copy the per-test + * temp home directory back there so that libdbus uses the same + * `$HOME/.dbus-keyrings` path as GLib. This is not thread-safe. */ + g_setenv ("HOME", g_get_home_dir (), TRUE); + libdbus_call.conn = dbus_connection_open_private (connectable_address, &libdbus_call.error); g_assert_cmpstr (libdbus_call.error.name, ==, NULL); @@ -516,10 +524,7 @@ int main (int argc, char *argv[]) { - /* FIXME: Add debug for https://gitlab.gnome.org/GNOME/glib/issues/1954 */ - g_setenv ("G_DBUS_DEBUG", "all", TRUE); - - g_test_init (&argc, &argv, NULL); + g_test_init (&argc, &argv, G_TEST_OPTION_ISOLATE_DIRS, NULL); g_test_add_func ("/gdbus/server-auth", test_server_auth); g_test_add_func ("/gdbus/server-auth/abstract", test_server_auth_abstract);