[glib] gmenumodel test: If something goes wrong, don't wait forever
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] gmenumodel test: If something goes wrong, don't wait forever
- Date: Mon, 18 Dec 2017 19:04:20 +0000 (UTC)
commit ea159a9e1a852246f51348ddc19353dc35727700
Author: Simon McVittie <smcv collabora com>
Date: Mon Dec 18 15:51:54 2017 +0000
gmenumodel test: If something goes wrong, don't wait forever
I'm about to add some loops that would otherwise wait indefinitely.
Signed-off-by: Simon McVittie <smcv collabora com>
Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=884661
https://bugzilla.gnome.org/show_bug.cgi?id=791744
gio/tests/gmenumodel.c | 30 ++++++++++++++++++++++++++++++
1 files changed, 30 insertions(+), 0 deletions(-)
---
diff --git a/gio/tests/gmenumodel.c b/gio/tests/gmenumodel.c
index 9072eea..fa26882 100644
--- a/gio/tests/gmenumodel.c
+++ b/gio/tests/gmenumodel.c
@@ -5,6 +5,33 @@
#include "gdbus-sessionbus.h"
+static gboolean
+time_out (gpointer unused G_GNUC_UNUSED)
+{
+ g_error ("Timed out");
+ /* not reached */
+ return FALSE;
+}
+
+static guint
+add_timeout (guint seconds)
+{
+#ifdef G_OS_UNIX
+ /* Safety-catch against the main loop having blocked */
+ alarm (seconds + 5);
+#endif
+ return g_timeout_add_seconds (seconds, time_out, NULL);
+}
+
+static void
+cancel_timeout (guint timeout_id)
+{
+#ifdef G_OS_UNIX
+ alarm (0);
+#endif
+ g_source_remove (timeout_id);
+}
+
/* Markup printing {{{1 */
/* This used to be part of GLib, but it was removed before the stable
@@ -1017,7 +1044,9 @@ do_subscriptions (GDBusConnection *exporter_connection,
GMainLoop *loop;
GError *error = NULL;
guint export_id;
+ guint timeout_id;
+ timeout_id = add_timeout (60);
loop = g_main_loop_new (NULL, FALSE);
menu = g_menu_new ();
@@ -1084,6 +1113,7 @@ do_subscriptions (GDBusConnection *exporter_connection,
g_object_unref (menu);
g_main_loop_unref (loop);
+ cancel_timeout (timeout_id);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]