[glib/wip/pwithnall/gdbus-names-livelock: 1/2] tests: Add missing wakeup calls to gdbus-names test




commit 8530a6a8e4d19c9e6eb238f6b9b0462a70df188d
Author: Philip Withnall <pwithnall endlessos org>
Date:   Tue Jun 15 12:57:00 2021 +0100

    tests: Add missing wakeup calls to gdbus-names test
    
    The tests in `gdbus-names.c` use a mixture of `GMainLoop` and iterating
    a `GMainContext` directly. Some of the helper functions based around the
    `OwnNameData` struct use the `loop` `GMainLoop` even when called from
    tests like `watch_with_different_context()` which themselves use
    `GMainContext` directly.
    
    Thus, it’s possible for the `GMainLoop` to not be running, while the
    test is iterating on `g_main_context_iteration()`. In this case,
    `g_main_loop_quit()` is a no-op and will not wake up the `GMainContext`.
    This causes the test to livelock in around 1 in 1200 test runs.
    
    Fix this by adding an explicit `g_main_context_wakeup()` call after each
    `g_main_loop_quit()` call. A more comprehensive fix would be to port all
    the tests in this file to iterating `GMainContext` directly, and drop
    all the `GMainLoop` usage, but I don’t have time for that right now.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>

 gio/tests/gdbus-names.c | 9 +++++++++
 1 file changed, 9 insertions(+)
---
diff --git a/gio/tests/gdbus-names.c b/gio/tests/gdbus-names.c
index 89bccb83d..26b7aa8e2 100644
--- a/gio/tests/gdbus-names.c
+++ b/gio/tests/gdbus-names.c
@@ -46,6 +46,7 @@ own_name_data_free_func (OwnNameData *data)
 {
   data->num_free_func++;
   g_main_loop_quit (loop);
+  g_main_context_wakeup (g_main_loop_get_context (loop));
 }
 
 static void
@@ -57,6 +58,7 @@ bus_acquired_handler (GDBusConnection *connection,
   g_dbus_connection_set_exit_on_close (connection, FALSE);
   data->num_bus_acquired += 1;
   g_main_loop_quit (loop);
+  g_main_context_wakeup (g_main_loop_get_context (loop));
 }
 
 static void
@@ -67,6 +69,7 @@ name_acquired_handler (GDBusConnection *connection,
   OwnNameData *data = user_data;
   data->num_acquired += 1;
   g_main_loop_quit (loop);
+  g_main_context_wakeup (g_main_loop_get_context (loop));
 }
 
 static void
@@ -86,6 +89,7 @@ name_lost_handler (GDBusConnection *connection,
     }
   data->num_lost += 1;
   g_main_loop_quit (loop);
+  g_main_context_wakeup (g_main_loop_get_context (loop));
 }
 
 static void
@@ -516,6 +520,7 @@ watch_name_data_free_func (WatchNameData *data)
 {
   data->num_free_func++;
   g_main_loop_quit (loop);
+  g_main_context_wakeup (g_main_loop_get_context (loop));
 }
 
 static void
@@ -533,6 +538,7 @@ w_name_acquired_handler (GDBusConnection *connection,
   OwnNameData *data = user_data;
   data->num_acquired += 1;
   g_main_loop_quit (loop);
+  g_main_context_wakeup (g_main_loop_get_context (loop));
 }
 
 static void
@@ -543,6 +549,7 @@ w_name_lost_handler (GDBusConnection *connection,
   OwnNameData *data = user_data;
   data->num_lost += 1;
   g_main_loop_quit (loop);
+  g_main_context_wakeup (g_main_loop_get_context (loop));
 }
 
 static void
@@ -564,6 +571,7 @@ name_appeared_handler (GDBusConnection *connection,
     }
   data->num_appeared += 1;
   g_main_loop_quit (loop);
+  g_main_context_wakeup (g_main_loop_get_context (loop));
 }
 
 static void
@@ -584,6 +592,7 @@ name_vanished_handler (GDBusConnection *connection,
     }
   data->num_vanished += 1;
   g_main_loop_quit (loop);
+  g_main_context_wakeup (g_main_loop_get_context (loop));
 }
 
 typedef struct


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