diff --git a/tests/modules/config-policy.c b/tests/modules/config-policy.c index 6ab71a695c74ce602bbff02c588587a638adc252..babc536e549cbabc59425b7beeb9f0d125f0e917 100644 --- a/tests/modules/config-policy.c +++ b/tests/modules/config-policy.c @@ -71,6 +71,8 @@ loop_thread_start (void *d) static void config_policy_setup (TestConfigPolicyFixture *self, gconstpointer user_data) { + gint64 end_time; + /* Data */ g_mutex_init (&self->mutex); g_cond_init (&self->cond); @@ -81,8 +83,13 @@ config_policy_setup (TestConfigPolicyFixture *self, gconstpointer user_data) /* Wait for everything to be created */ g_mutex_lock (&self->mutex); + end_time = g_get_monotonic_time () + 3 * G_TIME_SPAN_SECOND; while (!self->created) - g_cond_wait (&self->cond, &self->mutex); + if (!g_cond_wait_until (&self->cond, &self->mutex, end_time)) { + /* Abort when timeout has passed */ + g_warning ("Aborting due to timeout when waiting for connection"); + abort(); + } g_mutex_unlock (&self->mutex); } diff --git a/tests/modules/config-policy/context.c b/tests/modules/config-policy/context.c index e286a4ed7a786173bc997ec06a79ac2be2d0a3bb..def2d545d03e0d03451c0df3682175b8d752956b 100644 --- a/tests/modules/config-policy/context.c +++ b/tests/modules/config-policy/context.c @@ -39,11 +39,17 @@ G_DEFINE_TYPE (WpConfigPolicyContext, wp_config_policy_context, G_TYPE_OBJECT); static WpBaseEndpoint * wait_for_endpoint (WpConfigPolicyContext *self, WpBaseEndpointLink **link) { + gint64 end_time; g_mutex_lock (&self->mutex); /* Wait for endpoint to be set */ + end_time = g_get_monotonic_time () + 3 * G_TIME_SPAN_SECOND; while (!self->endpoint) - g_cond_wait (&self->cond, &self->mutex); + if (!g_cond_wait_until (&self->cond, &self->mutex, end_time)) { + /* Abort when timeout has passed */ + g_warning ("Aborting due to timeout when waiting for endpoint"); + abort(); + } /* Set endpoint to a local value and clear global value */ WpBaseEndpoint *endpoint = g_object_ref (self->endpoint);