From 79ef610f03938d1fed1677f9d1843d72e5a535b9 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Fri, 21 Feb 2020 12:08:57 +0000 Subject: [PATCH] tests: Wait until unsubscribing from a signal has completed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As with the previous commit, don’t stop iterating the `context` in `test_delivery_in_thread_func()` until the unsubscription from a signal is complete, and hence there’s a guarantee that no callbacks are pending in the `thread_context`. This commit uses the `GDestroyNotify` for `g_dbus_connection_signal_subscribe()` as a synchronisation message from the D-Bus worker thread to the `test_delivery_in_thread_func()` thread to notify of signal unsubscription. Signed-off-by: Philip Withnall Fixes: #1515 --- gio/tests/gdbus-threading.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/gio/tests/gdbus-threading.c b/gio/tests/gdbus-threading.c index b57888a78..159a008ab 100644 --- a/gio/tests/gdbus-threading.c +++ b/gio/tests/gdbus-threading.c @@ -82,6 +82,7 @@ typedef struct { GThread *thread; GMainLoop *thread_loop; guint signal_count; + gboolean unsubscribe_complete; } DeliveryData; static void @@ -147,6 +148,18 @@ signal_handler (GDBusConnection *connection, g_main_loop_quit (data->thread_loop); } +static void +signal_data_free_cb (gpointer user_data) +{ + DeliveryData *data = user_data; + + g_assert_true (g_thread_self () == data->thread); + + data->unsubscribe_complete = TRUE; + + g_main_loop_quit (data->thread_loop); +} + static gpointer test_delivery_in_thread_func (gpointer _data) { @@ -167,6 +180,7 @@ test_delivery_in_thread_func (gpointer _data) data.thread = g_thread_self (); data.thread_loop = thread_loop; data.signal_count = 0; + data.unsubscribe_complete = FALSE; /* ---------------------------------------------------------------------------------------------------- */ @@ -242,7 +256,7 @@ test_delivery_in_thread_func (gpointer _data) G_DBUS_SIGNAL_FLAGS_NONE, signal_handler, &data, - NULL); + signal_data_free_cb); g_assert_cmpuint (subscription_id, !=, 0); g_assert_cmpuint (data.signal_count, ==, 0); @@ -256,6 +270,10 @@ test_delivery_in_thread_func (gpointer _data) g_object_unref (priv_c); g_dbus_connection_signal_unsubscribe (c, subscription_id); + subscription_id = 0; + + g_main_loop_run (thread_loop); + g_assert_true (data.unsubscribe_complete); /* ---------------------------------------------------------------------------------------------------- */