[Telepathy-commits] [telepathy-salut/master] test-two-tubes.py: remove races in the test suite

Alban Crequy alban.crequy at collabora.co.uk
Tue Nov 25 03:59:42 PST 2008


---
 tests/twisted/avahi/test-two-tubes.py |   60 +++++++++++++++++++++++++++------
 1 files changed, 49 insertions(+), 11 deletions(-)

diff --git a/tests/twisted/avahi/test-two-tubes.py b/tests/twisted/avahi/test-two-tubes.py
index e6d82d8..0f3d2fb 100644
--- a/tests/twisted/avahi/test-two-tubes.py
+++ b/tests/twisted/avahi/test-two-tubes.py
@@ -61,37 +61,75 @@ def test(q, bus, conn):
             raise
     l = reactor.listenUNIX(server_socket_address, factory)
 
-    # first connection
+    # first connection: connect
+    contact1_name = "testsuite" + "@" + get_host_name()
     conn.Connect()
     q.expect('dbus-signal', signal='StatusChanged', args=[0L, 0L])
 
-    # second connection
+    # second connection: connect
     conn2_params = {
         'published-name': 'testsuite2',
         'first-name': 'test2',
         'last-name': 'suite2',
         }
+    contact2_name = "testsuite2" + "@" + get_host_name()
     conn2 = make_connection(bus, q.append, conn2_params)
     conn2.Connect()
     q.expect('dbus-signal', signal='StatusChanged', args=[0L, 0L])
-    contact2_name = "testsuite2" + "@" + get_host_name()
 
+    # first connection: get the contact list
     publish_handle = conn.RequestHandles(HT_CONTACT_LIST, ["publish"])[0]
-    publish = conn.RequestChannel(
+    conn1_publish = conn.RequestChannel(
         "org.freedesktop.Telepathy.Channel.Type.ContactList",
         HT_CONTACT_LIST, publish_handle, False)
+    conn1_publish_proxy = bus.get_object(conn.bus_name, conn1_publish)
 
-    handle = 0
-    # Wait until the record shows up in publish
-    while handle == 0:
-        e = q.expect('dbus-signal', signal='MembersChanged', path=publish)
+    # second connection: get the contact list
+    publish_handle = conn2.RequestHandles(HT_CONTACT_LIST, ["publish"])[0]
+    conn2_publish = conn2.RequestChannel(
+        "org.freedesktop.Telepathy.Channel.Type.ContactList",
+        HT_CONTACT_LIST, publish_handle, False)
+    conn2_publish_proxy = bus.get_object(conn2.bus_name, conn2_publish)
+
+    # first connection: wait to see contact2
+    # The signal MembersChanged may be already emitted... check the Members
+    # property first
+    contact2_handle_on_conn1 = 0
+    conn1_members = conn1_publish_proxy.Get(
+            'org.freedesktop.Telepathy.Channel.Interface.Group', 'Members',
+            dbus_interface='org.freedesktop.DBus.Properties')
+    for h in conn1_members:
+        name = conn.InspectHandles(HT_CONTACT, [h])[0]
+        if name == contact2_name:
+            contact2_handle_on_conn1 = h
+    while contact2_handle_on_conn1 == 0:
+        e = q.expect('dbus-signal', signal='MembersChanged', path=conn1_publish)
         for h in e.args[1]:
             name = conn.InspectHandles(HT_CONTACT, [h])[0]
             if name == contact2_name:
-                handle = h
+                contact2_handle_on_conn1 = h
+
+    # second connection: wait to see contact1
+    # The signal MembersChanged may be already emitted... check the Members
+    # property first
+    contact1_handle_on_conn2 = 0
+    conn2_members = conn2_publish_proxy.Get(
+            'org.freedesktop.Telepathy.Channel.Interface.Group', 'Members',
+            dbus_interface='org.freedesktop.DBus.Properties')
+    for h in conn2_members:
+        name = conn.InspectHandles(HT_CONTACT, [h])[0]
+        if name == contact1_name:
+            contact1_handle_on_conn2 = h
+    while contact1_handle_on_conn2 == 0:
+        e = q.expect('dbus-signal', signal='MembersChanged', path=conn2_publish)
+        for h in e.args[1]:
+            name = conn2.InspectHandles(HT_CONTACT, [h])[0]
+            if name == contact1_name:
+                contact1_handle_on_conn2 = h
 
-    t = conn.RequestChannel(CHANNEL_TYPE_TUBES, HT_CONTACT, handle,
-        True)
+    # do tubes
+    t = conn.RequestChannel(CHANNEL_TYPE_TUBES, HT_CONTACT,
+            contact2_handle_on_conn1, True)
     contact1_tubes_channel = make_channel_proxy(conn, t, "Channel.Type.Tubes")
 
     tube_id = contact1_tubes_channel.OfferStreamTube("http", sample_parameters,
-- 
1.5.6.5




More information about the Telepathy-commits mailing list