[telepathy-gabble/master] Unrace test-vcard-race

Will Thompson will.thompson at collabora.co.uk
Sun Aug 9 02:26:47 PDT 2009


This makes test-vcard-race actually test the intended feature, namely
coalescing vCard updates while there's an outstanding vCard request.
There were two races:

 * The vCard reply sent in response to Gabble's query during connection
   sometimes reached Gabble after the call to SetAliases;
 * The call to SetAvatar sometimes reached Gabble after the reply to the
   vCard request made by SetAliases.

The "wrong" outcome of both races actually reveals an assertion failure
in Gabble; reliable test to follow.
---
 tests/twisted/vcard/test-vcard-race.py |   38 ++++++++++++++++++++++++-------
 1 files changed, 29 insertions(+), 9 deletions(-)

diff --git a/tests/twisted/vcard/test-vcard-race.py b/tests/twisted/vcard/test-vcard-race.py
index 78e4e49..2b1b872 100644
--- a/tests/twisted/vcard/test-vcard-race.py
+++ b/tests/twisted/vcard/test-vcard-race.py
@@ -17,26 +17,46 @@ import base64
 
 from twisted.words.xish import xpath
 
-from servicetest import call_async
+from servicetest import call_async, sync_dbus
 from gabbletest import (
-    exec_test, expect_and_handle_get_vcard, expect_and_handle_set_vcard)
+    exec_test, expect_and_handle_get_vcard, expect_and_handle_set_vcard,
+    make_result_iq, sync_stream,
+    )
+import ns
 
 def test(q, bus, conn, stream):
     conn.Connect()
 
     expect_and_handle_get_vcard(q, stream)
 
-    call_async(q, conn, 'GetSelfHandle')
-    event = q.expect('dbus-return', method='GetSelfHandle')
-    handle = event.value[0]
+    # Ensure that Gabble's actually got the initial vCard reply; if it hasn't
+    # processed it by the time we call SetAliases, the latter will wait for it
+    # to reply and then set immediately.
+    sync_stream(q, stream)
+
+    handle = conn.GetSelfHandle()
 
     call_async(q, conn.Aliasing, 'SetAliases', {handle: 'Some Guy'})
+
+    # SetAliases requests vCard v1
+    get_vcard_event = q.expect('stream-iq', query_ns=ns.VCARD_TEMP,
+        query_name='vCard', iq_type='get')
+
+    iq = get_vcard_event.stanza
+    vcard = iq.firstChildElement()
+    assert vcard.name == 'vCard', vcard.toXml()
+
     call_async(q, conn.Avatars, 'SetAvatar', 'hello', 'image/png')
 
-    # Gabble asks for the self-vCard again (FIXME: why? Interestingly, when I
-    # called GetSelfHandle synchronously Gabble *didn't* ask for the vCard
-    # again.)
-    expect_and_handle_get_vcard(q, stream)
+    # We don't expect Gabble to send a second vCard request, since there's one
+    # outstanding. But we want to ensure that SetAvatar reaches Gabble before
+    # the empty vCard does.
+    sync_dbus(bus, q, conn)
+
+    # Send back current empty vCard
+    result = make_result_iq(stream, iq)
+    # result already includes the <vCard/> from the query, which is all we need
+    stream.send(result)
 
     def has_nickname_and_photo(vcard):
         nicknames = xpath.queryForNodes('/vCard/NICKNAME', vcard)
-- 
1.5.6.5




More information about the telepathy-commits mailing list