[next] telepathy-glib: contacts test: don' t create contacts til after the signal we want to avoid

Simon McVittie smcv at kemper.freedesktop.org
Tue Mar 18 05:45:05 PDT 2014


Module: telepathy-glib
Branch: next
Commit: c64fcf3bbf80b99bcd6273ad967d5651fb26fb02
URL:    http://cgit.freedesktop.org/telepathy/telepathy-glib/commit/?id=c64fcf3bbf80b99bcd6273ad967d5651fb26fb02

Author: Simon McVittie <simon.mcvittie at collabora.co.uk>
Date:   Thu Mar 13 19:12:03 2014 +0000

contacts test: don't create contacts til after the signal we want to avoid

In each of these test cases we're trying to create a contact that
does not know a particular piece of information. However, TpContact
opportunistically fills in pieces of information that it sees in
signals that go past, and tp_tests_contacts_connection_change_*()
do emit signals.

Previously, we got away with it; I'm not sure how. Perhaps
tp_connection_upgrade_contacts_async() always returned before the
signal was received?

---

 tests/dbus/contacts.c |   38 ++++++++++++++++++++++++++++++--------
 1 file changed, 30 insertions(+), 8 deletions(-)

diff --git a/tests/dbus/contacts.c b/tests/dbus/contacts.c
index b394fe4..3261858 100644
--- a/tests/dbus/contacts.c
+++ b/tests/dbus/contacts.c
@@ -230,17 +230,25 @@ contact_info_request_cancel (gpointer cancellable)
   return FALSE;
 }
 
+static TpHandle
+ensure_handle (Fixture *f,
+    const gchar *id)
+{
+  TpBaseConnection *service_conn = (TpBaseConnection *) f->service_conn;
+  TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (
+      service_conn, TP_ENTITY_TYPE_CONTACT);
+
+  return tp_handle_ensure (contact_repo, id, NULL, NULL);
+}
+
 static TpContact *
 ensure_contact (Fixture *f,
     const gchar *id,
     TpHandle *handle)
 {
-  TpBaseConnection *service_conn = (TpBaseConnection *) f->service_conn;
   TpConnection *client_conn = f->client_conn;
-  TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (
-      service_conn, TP_ENTITY_TYPE_CONTACT);
 
-  *handle = tp_handle_ensure (contact_repo, id, NULL, NULL);
+  *handle = ensure_handle (f, id);
   return tp_connection_dup_contact_if_possible (client_conn, *handle, id);
 }
 
@@ -320,10 +328,19 @@ test_contact_info (Fixture *f,
   g_object_unref (contact);
 
   /* TEST 4: First set the info in the CM for an handle, then create a TpContact
-   * without INFO feature, and finally refresh the contact's info. */
-  contact = ensure_contact (f, "info-test-4", &handle);
+   * without INFO feature, and finally refresh the contact's info.
+   *
+   * We can't use ensure_contact() because that would create the contact
+   * before we change its contact info, and changing its contact info
+   * emits a signal. If we receive that signal while the contact exists,
+   * we'll opportunistically fill in its contact info, and the assertion
+   * that it has no contact info fails. */
+  handle = ensure_handle (f, "info-test-4");
   tp_tests_contacts_connection_change_contact_info (service_conn, handle,
       info);
+  tp_tests_proxy_run_until_dbus_queue_processed (client_conn);
+  contact = tp_connection_dup_contact_if_possible (client_conn, handle,
+      "info-test-4");
 
   tp_connection_upgrade_contacts_async (client_conn,
       1, &contact, NULL,
@@ -1787,12 +1804,17 @@ test_no_location (Fixture *f,
 
   /* Check that first retrieving a contact without the LOCATION feature, and
    * later upgrading it to have the LOCATION feature, does the right thing.
-   */
-  contact = ensure_contact (f, "rupert", &handle);
+   * As with "TEST 4" in the location tests, we must defer creating the
+   * contact until after we have changed its location at the service side. */
+  handle = ensure_handle (f, "rupert");
   g_assert_cmpuint (handle, !=, 0);
 
   tp_tests_contacts_connection_change_locations (f->service_conn,
       1, &handle, &norway);
+  tp_tests_proxy_run_until_dbus_queue_processed (f->client_conn);
+
+  contact = tp_connection_dup_contact_if_possible (f->client_conn, handle,
+      "rupert");
 
   tp_connection_upgrade_contacts_async (f->client_conn,
       1, &contact, NULL,



More information about the telepathy-commits mailing list