[glib: 3/4] tests: Use g_idle_add to call g_main_loop_quit



commit f2888984854d90fabf56aee51b9f40736996e82f
Author: Ting-Wei Lan <lantw src gnome org>
Date:   Sun Jun 3 20:51:31 2018 +0800

    tests: Use g_idle_add to call g_main_loop_quit
    
    Sometimes file monitor events may be slow to emit. Using g_idle_add
    makes it less possible for events to be scheduled later than the main
    loop quit, preventing test failure caused by missing events.
    
    This fixes test failure on FreeBSD.

 gio/tests/monitor.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
---
diff --git a/gio/tests/monitor.c b/gio/tests/monitor.c
index 69eae346b..4d64fa826 100644
--- a/gio/tests/monitor.c
+++ b/gio/tests/monitor.c
@@ -84,6 +84,19 @@ delete_file_idle (gpointer data)
   return G_SOURCE_REMOVE;
 }
 
+static gboolean
+stop_loop_idle (gpointer data)
+{
+  MonitorData *d = data;
+
+  g_assert (d->state == 6);
+
+  if (d->loop)
+    g_main_loop_quit (d->loop);
+
+  return G_SOURCE_REMOVE;
+}
+
 static void
 changed_cb (GFileMonitor      *monitor,
             GFile             *file,
@@ -112,8 +125,7 @@ changed_cb (GFileMonitor      *monitor,
     case 5:
       g_assert (event == G_FILE_MONITOR_EVENT_DELETED);
       d->state = 6;
-      if (d->loop)
-        g_main_loop_quit (d->loop);
+      g_idle_add (stop_loop_idle, data);
       break;
     default:
       g_assert_not_reached ();


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