summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Lortie <desrt@desrt.ca>2012-07-11 11:24:18 -0400
committerRyan Lortie <desrt@desrt.ca>2012-07-11 11:24:18 -0400
commit334daf4624fcb6bc72f4b19f3bb7ecaf9b4ee347 (patch)
treebb1148c19466c42ee8773f1efdc35e63975181be
parentb1cf066711a06526e66bd0b271ec49c9416add9d (diff)
downloaddconf-334daf4624fcb6bc72f4b19f3bb7ecaf9b4ee347.tar.gz
dbus test: use GMainContext instead of GCond
Wait for the async results to finish using a GMainContext for signalling instead of a GCond. This will let other things run in the mainloop in the meanwhile (which will be important when we add the libdbus-1 backend for testing).
-rw-r--r--tests/dbus.c74
1 files changed, 48 insertions, 26 deletions
diff --git a/tests/dbus.c b/tests/dbus.c
index d8c54ad..7541769 100644
--- a/tests/dbus.c
+++ b/tests/dbus.c
@@ -13,9 +13,49 @@ static GThread *dbus_thread;
static GQueue async_call_success_queue;
static GQueue async_call_error_queue;
static GMutex async_call_queue_lock;
-static GCond async_call_queue_cond;
static gboolean signal_was_received;
+static void
+wait_for_queue_to_empty (GQueue *queue)
+{
+ okay_in_main = TRUE;
+
+ while (TRUE)
+ {
+ gboolean is_empty;
+
+ g_mutex_lock (&async_call_queue_lock);
+ is_empty = g_queue_is_empty (queue);
+ g_mutex_unlock (&async_call_queue_lock);
+
+ if (is_empty)
+ return;
+
+ g_main_context_iteration (NULL, TRUE);
+ }
+
+ okay_in_main = FALSE;
+}
+
+static gboolean
+just_wake (gpointer user_data)
+{
+ return G_SOURCE_REMOVE;
+}
+
+static void
+signal_if_queue_is_empty (GQueue *queue)
+{
+ gboolean is_empty;
+
+ g_mutex_lock (&async_call_queue_lock);
+ is_empty = g_queue_is_empty (queue);
+ g_mutex_unlock (&async_call_queue_lock);
+
+ if (is_empty)
+ g_idle_add (just_wake, NULL);
+}
+
void
dconf_engine_call_handle_reply (DConfEngineCallHandle *handle,
GVariant *parameters,
@@ -53,10 +93,7 @@ dconf_engine_call_handle_reply (DConfEngineCallHandle *handle,
g_assert (expected_handle == handle);
g_free (handle);
- g_mutex_lock (&async_call_queue_lock);
- if (g_queue_is_empty (&async_call_success_queue))
- g_cond_broadcast (&async_call_queue_cond);
- g_mutex_unlock (&async_call_queue_lock);
+ signal_if_queue_is_empty (&async_call_success_queue);
}
else
{
@@ -71,10 +108,7 @@ dconf_engine_call_handle_reply (DConfEngineCallHandle *handle,
g_assert (expected_handle == handle);
g_free (handle);
- g_mutex_lock (&async_call_queue_lock);
- if (g_queue_is_empty (&async_call_error_queue))
- g_cond_broadcast (&async_call_queue_cond);
- g_mutex_unlock (&async_call_queue_lock);
+ signal_if_queue_is_empty (&async_call_error_queue);
}
}
@@ -169,10 +203,7 @@ test_creation_error (void)
{
g_assert_no_error (error);
- g_mutex_lock (&async_call_queue_lock);
- while (!g_queue_is_empty (&async_call_error_queue))
- g_cond_wait (&async_call_queue_cond, &async_call_queue_lock);
- g_mutex_unlock (&async_call_queue_lock);
+ wait_for_queue_to_empty (&async_call_error_queue);
}
else
g_assert (error != NULL);
@@ -274,10 +305,7 @@ test_async_call_success (void)
g_assert (success);
}
- g_mutex_lock (&async_call_queue_lock);
- while (!g_queue_is_empty (&async_call_success_queue))
- g_cond_wait (&async_call_queue_cond, &async_call_queue_lock);
- g_mutex_unlock (&async_call_queue_lock);
+ wait_for_queue_to_empty (&async_call_success_queue);
}
static void
@@ -295,14 +323,11 @@ test_async_call_error (void)
success = dconf_engine_dbus_call_async_func (G_BUS_TYPE_SESSION,
"org.freedesktop.DBus", "/", "org.freedesktop.DBus", "GetId",
- g_variant_new ("(u)", 4), handle, &error);
+ g_variant_new ("(s)", ""), handle, &error);
g_assert_no_error (error);
g_assert (success);
- g_mutex_lock (&async_call_queue_lock);
- while (!g_queue_is_empty (&async_call_error_queue))
- g_cond_wait (&async_call_queue_cond, &async_call_queue_lock);
- g_mutex_unlock (&async_call_queue_lock);
+ wait_for_queue_to_empty (&async_call_error_queue);
}
static void
@@ -331,10 +356,7 @@ test_sync_during_async (void)
g_assert (reply != NULL);
g_variant_unref (reply);
- g_mutex_lock (&async_call_queue_lock);
- while (!g_queue_is_empty (&async_call_success_queue))
- g_cond_wait (&async_call_queue_cond, &async_call_queue_lock);
- g_mutex_unlock (&async_call_queue_lock);
+ wait_for_queue_to_empty (&async_call_success_queue);
}
static void