From b350a814a2b9f1cdb96a348ed3b335077b35bc3d Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 31 May 2018 14:08:50 +0100 Subject: [PATCH 20/39] test: Add a function to catch up with pending messages This is very loosely based on test infrastructure that used to exist in Telepathy. It arranges for all prior messages on both the connections to have been processed, by making use of total ordering: if caller sends method call M1 to callee, and callee sends back a reply M2, then all messages received by callee prior to M1, received by caller prior to M2, sent by callee prior to M2 or sent by caller prior to M1 are also guaranteed to have been processed. Signed-off-by: Simon McVittie --- test/test-utils-glib.c | 39 +++++++++++++++++++++++++++++++++++++++ test/test-utils-glib.h | 2 ++ 2 files changed, 41 insertions(+) diff --git a/test/test-utils-glib.c b/test/test-utils-glib.c index cfdbb38e..81727a1d 100644 --- a/test/test-utils-glib.c +++ b/test/test-utils-glib.c @@ -778,3 +778,42 @@ test_store_result_cb (GObject *source_object G_GNUC_UNUSED, g_assert_null (*result_p); *result_p = g_object_ref (result); } + +/* + * Send a Ping() call from a sender to a destination, and wait for the + * destination to reply. By the time we get the reply, the destination + * must have received any prior signals from the sender that it was + * going to receive, and similarly the sender must have received any + * prior signals from the destination. + */ +void +test_sync_gdbus_connections (GDBusConnection *caller, + GDBusConnection *callee) +{ + GVariant *tuple; + GError *error = NULL; + GAsyncResult *result = NULL; + + g_return_if_fail (G_IS_DBUS_CONNECTION (caller)); + g_return_if_fail (G_IS_DBUS_CONNECTION (callee)); + + g_test_message ("Synchronizing caller %p with callee %p...", caller, callee); + + g_dbus_connection_call (caller, + g_dbus_connection_get_unique_name (callee), + "/", DBUS_INTERFACE_PEER, "Ping", + NULL, G_VARIANT_TYPE_UNIT, + G_DBUS_CALL_FLAGS_NONE, -1, NULL, + test_store_result_cb, &result); + + while (result == NULL) + g_main_context_iteration (NULL, TRUE); + + tuple = g_dbus_connection_call_finish (caller, result, &error); + + g_assert_no_error (error); + g_assert_nonnull (tuple); + g_variant_unref (tuple); + + g_test_message ("Synchronized caller %p with callee %p", caller, callee); +} diff --git a/test/test-utils-glib.h b/test/test-utils-glib.h index 7e65b629..1795f741 100644 --- a/test/test-utils-glib.h +++ b/test/test-utils-glib.h @@ -124,5 +124,7 @@ backported_g_steal_pointer (gpointer pointer_to_pointer) void test_store_result_cb (GObject *source_object, GAsyncResult *result, gpointer user_data); +void test_sync_gdbus_connections (GDBusConnection *caller, + GDBusConnection *callee); #endif -- 2.17.0