[Telepathy-commits] [telepathy-gabble/master] Unrace test-wait-for-caps; test both outcomes instead
Will Thompson
will.thompson at collabora.co.uk
Wed Feb 4 08:41:06 PST 2009
Previously the test tried to ensure that RequestStreams had been
received by Gabble before sending the contact's presence, but like in
f861770 sending a spurious presence update doesn't actually guarantee
that. So sometimes Gabble received RequestStreams before getting the
presence, and sometimes afterwards (which in practice was still before
the disco reply, although that wasn't guaranteed). Now, test both cases.
---
tests/twisted/jingle/test-wait-for-caps.py | 82 ++++++++++++++++------------
1 files changed, 46 insertions(+), 36 deletions(-)
diff --git a/tests/twisted/jingle/test-wait-for-caps.py b/tests/twisted/jingle/test-wait-for-caps.py
index da0b179..b967bde 100644
--- a/tests/twisted/jingle/test-wait-for-caps.py
+++ b/tests/twisted/jingle/test-wait-for-caps.py
@@ -1,4 +1,3 @@
-
"""
Test use-case when client requests going online and immediately
attempts to call a contact. Gabble should delay the RequestStreams
@@ -7,10 +6,11 @@ call until caps have arrived.
from gabbletest import exec_test, make_result_iq, sync_stream
from servicetest import make_channel_proxy, unwrap, tp_path_prefix, \
- call_async, EventPattern
+ call_async, EventPattern, sync_dbus
from twisted.words.xish import domish
import jingletest
import gabbletest
+
import dbus
import time
@@ -19,11 +19,10 @@ import ns
def test(q, bus, conn, stream):
jt = jingletest.JingleTest(stream, 'test at localhost', 'foo at bar.com/Foo')
+ jt2 = jingletest.JingleTest(stream, 'test at localhost', 'foo2 at bar.com/Foo')
+ # Make gabble think this is a different client
+ jt2.remote_caps['node'] = 'http://example.com/fake-client1'
- # If we need to override remote caps, feats, codecs or caps,
- # this is a good time to do it
-
- # Connecting
conn.Connect()
q.expect('dbus-signal', signal='StatusChanged', args=[1, 1])
@@ -33,51 +32,62 @@ def test(q, bus, conn, stream):
args=[{1L: (0L, {u'available': {}})}])
q.expect('dbus-signal', signal='StatusChanged', args=[0, 1])
- self_handle = conn.GetSelfHandle()
+ run_test(q, bus, conn, stream, jt, True)
+ run_test(q, bus, conn, stream, jt2, False)
+
+ conn.Disconnect()
+ q.expect('dbus-signal', signal='StatusChanged', args=[2, 1])
+
+def run_test(q, bus, conn, stream, jt, request_before_presence):
+ """
+ Requests streams on a media channel to jt.remote_jid, either before their
+ presence is received (if request_before_presence is True) or after their
+ presence is received but before we've got a disco response for their
+ capabilities (otherwise).
+ """
# We intentionally DON'T set remote presence yet. Since Gabble is still
# unsure whether to treat contact as offline for this purpose, it
# will tentatively allow channel creation and contact handle addition
- handle = conn.RequestHandles(cs.HT_CONTACT, [jt.remote_jid])[0]
-
- path = conn.RequestChannel(cs.CHANNEL_TYPE_STREAMED_MEDIA, cs.HT_CONTACT,
- handle, True)
+ request = dbus.Dictionary({ cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_STREAMED_MEDIA,
+ cs.TARGET_HANDLE_TYPE: cs.HT_CONTACT,
+ cs.TARGET_ID: jt.remote_jid
+ }, signature='sv')
+ path, props = conn.CreateChannel(request, dbus_interface=cs.CONN_IFACE_REQUESTS)
media_iface = make_channel_proxy(conn, path, 'Channel.Type.StreamedMedia')
+ handle = props[cs.TARGET_HANDLE]
- # Now we request streams before either <presence> or caps have arrived
- call_async(q, media_iface, 'RequestStreams', handle, [0]) # req audio stream
+ sync_dbus(bus, q, conn)
- # Variant of the "make sure disco is processed" test hack, but this time
- # we want to make sure RequestStreams is processed (and suspended) before
- # presence arrives, to be able to test it properl.y
- el = domish.Element(('jabber.client', 'presence'))
- el['from'] = 'bob at example.com/Bar'
- stream.send(el.toXml())
- q.expect('dbus-signal', signal='PresenceUpdate')
- # OK, now we can continue. End of hack
+ def call_request_streams():
+ call_async(q, media_iface, 'RequestStreams', handle,
+ [cs.MEDIA_STREAM_TYPE_AUDIO])
- # Only now we send the presence and capabilities. Gabble should catch
- # this, disco caps, update caps and finally re-process RequestStreams
+ def send_presence():
+ jt.send_remote_presence()
+ return q.expect('stream-iq', query_ns=ns.DISCO_INFO, to=jt.remote_jid)
- # We need remote end's presence for capabilities
- jt.send_remote_presence()
+ if request_before_presence:
+ # Request streams before either <presence> or caps have arrived. Gabble
+ # should wait for both to arrive before returning from RequestStreams.
+ call_request_streams()
- # Gabble doesn't trust it, so makes a disco
- event = q.expect('stream-iq', query_ns=ns.DISCO_INFO, to='foo at bar.com/Foo')
+ # Ensure Gabble's received the method call.
+ sync_dbus(bus, q, conn)
- jt.send_remote_disco_reply(event.stanza)
+ # Now send the presence.
+ info_event = send_presence()
+ else:
+ info_event = send_presence()
- # RequestStreams should now happily complete
- q.expect('dbus-return', method='RequestStreams')
-
- # Test completed, close the connection
-
- conn.Disconnect()
- q.expect('dbus-signal', signal='StatusChanged', args=[2, 1])
+ # Now call RequestStreams; it should wait for the disco reply.
+ call_request_streams()
- return True
+ jt.send_remote_disco_reply(info_event.stanza)
+ # RequestStreams should now happily complete
+ q.expect('dbus-return', method='RequestStreams')
if __name__ == '__main__':
exec_test(test, timeout=10)
--
1.5.6.5
More information about the telepathy-commits
mailing list