summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiels De Graef <nielsdegraef@gmail.com>2021-01-15 20:46:18 +0100
committerNiels De Graef <nielsdegraef@gmail.com>2021-01-15 20:46:18 +0100
commit9c65f7dae1cc2468165bc9e1637e65da92df1c51 (patch)
tree5a711b2eaac4ad6d4e6539c891e291a3a4f4b8c9
parentcc6624e520637fd8493b9402da073cf8c859e988 (diff)
downloadgcr-wip/nielsdg/fix-tests-with-racy-gtask.tar.gz
Create a workaround for tests and GTaskwip/nielsdg/fix-tests-with-racy-gtask
It's possible that a GTask that has been called with `g_task_run_in_thread()` still has a reference held by that thread after the `_finish()` function has been called. This is a little problematic for tests that check for the final reference, so use this as a workaround instead. See https://gitlab.gnome.org/GNOME/glib/-/issues/1346 for more info
-rw-r--r--egg/egg-testing.h13
-rw-r--r--gcr/test-subject-public-key.c15
2 files changed, 22 insertions, 6 deletions
diff --git a/egg/egg-testing.h b/egg/egg-testing.h
index 73939b3..a98a782 100644
--- a/egg/egg-testing.h
+++ b/egg/egg-testing.h
@@ -61,4 +61,17 @@ gboolean egg_test_wait_until (int timeout);
gint egg_tests_run_with_loop (void);
+/* It's possible that a GTask that has been called with g_task_run_in_thread()
+ * still has a reference held by that thread after the _finish() function has
+ * been called. This is a little problematic for tests that check for the
+ * final reference, so use this as a workaround instead.
+ *
+ * See https://gitlab.gnome.org/GNOME/glib/-/issues/1346 for more info
+ */
+#define egg_test_wait_for_gtask_thread(expr) G_STMT_START \
+ while (expr) { \
+ g_main_context_iteration (NULL, FALSE); \
+ } \
+ G_STMT_END
+
#endif /* EGG_DH_H_ */
diff --git a/gcr/test-subject-public-key.c b/gcr/test-subject-public-key.c
index f92995a..4d16a7b 100644
--- a/gcr/test-subject-public-key.c
+++ b/gcr/test-subject-public-key.c
@@ -255,9 +255,11 @@ teardown_module (TestModule *test,
CK_RV rv;
g_object_unref (test->session);
- g_assert (test->session == NULL);
-
g_object_unref (test->module);
+
+ egg_test_wait_for_gtask_thread (test->session || test->module);
+
+ g_assert (test->session == NULL);
g_assert (test->module == NULL);
rv = (test->funcs.C_Finalize) (NULL);
@@ -307,12 +309,13 @@ teardown_loading (TestLoading *test,
gconstpointer fixture)
{
g_object_unref (test->crt_object);
- g_assert (test->crt_object == NULL);
-
g_object_unref (test->prv_object);
- g_assert (test->prv_object == NULL);
-
g_object_unref (test->pub_object);
+
+ egg_test_wait_for_gtask_thread (test->crt_object || test->prv_object || test->pub_object);
+
+ g_assert (test->crt_object == NULL);
+ g_assert (test->prv_object == NULL);
g_assert (test->pub_object == NULL);
teardown_module (&test->mo, NULL);