[glib/wip/pwithnall/ci-fixes] tests: Add more debug output to gdbus-threading test



commit 4d237daf324bc3f64eca4e0a2e233eb39235309b
Author: Philip Withnall <pwithnall endlessos org>
Date:   Fri Mar 4 19:53:04 2022 +0000

    tests: Add more debug output to gdbus-threading test
    
    It periodically hangs due to the `GDBusConnection` having more than 1
    ref (and never losing them), so there’s potentially a leaking ref
    somewhere:
    ```
    (/builds/alexander.klauer/glib/_build/gio/tests/gdbus-threading:17767): GLib-GIO-DEBUG: 13:18:12.268: 
refcount of 0x55fe85b1a260 is not right, sleeping
    \# GLib-GIO-DEBUG: refcount of 0x55fe85b1a260 is not right, sleeping
    ```
    
    Add some more debug output to try and track the problem down.
    
    See: https://gitlab.gnome.org/alexander.klauer/glib/-/jobs/1865968
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>

 gio/tests/gdbus-threading.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
---
diff --git a/gio/tests/gdbus-threading.c b/gio/tests/gdbus-threading.c
index 9f3abc430..23dc1fde3 100644
--- a/gio/tests/gdbus-threading.c
+++ b/gio/tests/gdbus-threading.c
@@ -48,8 +48,9 @@ timeout_cb (gpointer user_data)
  * unrefs complete first. This is typically used on the shared connection, to
  * ensure it’s in a correct state before beginning the next test. */
 static void
-assert_connection_has_one_ref (GDBusConnection *connection,
-                               GMainContext    *context)
+(assert_connection_has_one_ref) (GDBusConnection *connection,
+                                 GMainContext    *context,
+                                 const gchar     *calling_function)
 {
   GSource *timeout_source = NULL;
   TimeoutData data = { context, FALSE };
@@ -63,7 +64,8 @@ assert_connection_has_one_ref (GDBusConnection *connection,
 
   while (g_atomic_int_get (&G_OBJECT (connection)->ref_count) != 1 && !data.timed_out)
     {
-      g_debug ("refcount of %p is not right, sleeping", connection);
+      g_debug ("refcount of %p is not right (%u rather than 1) in %s(), sleeping",
+               connection, g_atomic_int_get (&G_OBJECT (connection)->ref_count), calling_function);
       g_main_context_iteration (NULL, TRUE);
     }
 
@@ -71,9 +73,14 @@ assert_connection_has_one_ref (GDBusConnection *connection,
   g_source_unref (timeout_source);
 
   if (g_atomic_int_get (&G_OBJECT (connection)->ref_count) != 1)
-    g_error ("connection %p had too many refs", connection);
+    g_error ("connection %p had too many refs (%u rather than 1) in %s()",
+             connection, g_atomic_int_get (&G_OBJECT (connection)->ref_count), calling_function);
 }
 
+/* Macro wrapper to add in the calling function name */
+#define assert_connection_has_one_ref(connection, context) \
+  (assert_connection_has_one_ref) (connection, context, G_STRFUNC)
+
 /* ---------------------------------------------------------------------------------------------------- */
 /* Ensure that signal and method replies are delivered in the right thread */
 /* ---------------------------------------------------------------------------------------------------- */


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