mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-14 13:26:16 +01:00
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: https://bugzilla.gnome.org/show_bug.cgi?id=791744 Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=884661
This commit is contained in:
parent
2fc3948ba7
commit
003c392a3b
@ -2,6 +2,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
|
||||
@ -818,7 +845,9 @@ test_dbus_subscriptions (void)
|
||||
GMainLoop *loop;
|
||||
GError *error = NULL;
|
||||
guint export_id;
|
||||
guint timeout_id;
|
||||
|
||||
timeout_id = add_timeout (60);
|
||||
loop = g_main_loop_new (NULL, FALSE);
|
||||
|
||||
bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
|
||||
@ -883,6 +912,7 @@ test_dbus_subscriptions (void)
|
||||
|
||||
g_main_loop_unref (loop);
|
||||
g_object_unref (bus);
|
||||
cancel_timeout (timeout_id);
|
||||
}
|
||||
|
||||
static gpointer
|
||||
|
Loading…
Reference in New Issue
Block a user