[Telepathy-commits] [telepathy-gabble/master] Replace test-group-race with a test using the new test API
Will Thompson
will.thompson at collabora.co.uk
Thu Sep 18 10:57:24 PDT 2008
In the process, fix a race condition in the test itself!
---
tests/twisted/roster/request-never-answered.py | 53 ++++++++++++++++++++
tests/twisted/test-group-race.py | 62 ------------------------
2 files changed, 53 insertions(+), 62 deletions(-)
create mode 100644 tests/twisted/roster/request-never-answered.py
delete mode 100644 tests/twisted/test-group-race.py
diff --git a/tests/twisted/roster/request-never-answered.py b/tests/twisted/roster/request-never-answered.py
new file mode 100644
index 0000000..deb3776
--- /dev/null
+++ b/tests/twisted/roster/request-never-answered.py
@@ -0,0 +1,53 @@
+"""
+Exhibit a bug where RequestChannel times out when requesting a group channel
+if the roster hasn't been received at the time of the call.
+"""
+
+import dbus
+
+from gabbletest import exec_test, sync_stream
+from servicetest import sync_dbus, call_async
+
+HT_GROUP = 4
+
+def test(q, bus, conn, stream):
+ conn.Connect()
+ # q.expect('dbus-signal', signal='StatusChanged', args=[0, 1])
+
+ roster_event = q.expect('stream-iq', query_ns='jabber:iq:roster')
+ roster_event.stanza['type'] = 'result'
+
+ call_async(q, conn, "RequestHandles", HT_GROUP, ['test'])
+
+ event = q.expect('dbus-return', method='RequestHandles')
+ test_handle = event.value[0][0]
+
+ call_async(q, conn, 'RequestChannel',
+ 'org.freedesktop.Telepathy.Channel.Type.ContactList', HT_GROUP,
+ test_handle, True)
+
+ # A previous incarnation of this test --- written with the intention that
+ # RequestChannel would be called before the roster was received, to expose
+ # a bug in Gabble triggered by that ordering --- was racy: if the D-Bus
+ # daemon happened to be particularly busy, the call to RequestChannel
+ # reached Gabble after the roster stanza. (The race was discovered when
+ # that reversed order triggered a newly-introduced instance of the
+ # opposite bug to the one the test was targetting!) So we sync the XMPP
+ # stream and D-Bus queue here.
+ sync_stream(q, stream)
+ sync_dbus(bus, q, conn)
+
+ # send an empty roster
+ stream.send(roster_event.stanza)
+
+ while True:
+ event = q.expect('dbus-signal', signal='NewChannel')
+ path, type, handle_type, handle, suppress_handler = event.args
+ if handle_type == HT_GROUP and handle == test_handle:
+ break;
+
+ event = q.expect('dbus-return', method='RequestChannel')
+ assert event.value[0] == path, (event.args[0], path)
+
+if __name__ == '__main__':
+ exec_test(test)
diff --git a/tests/twisted/test-group-race.py b/tests/twisted/test-group-race.py
deleted file mode 100644
index d73ef58..0000000
--- a/tests/twisted/test-group-race.py
+++ /dev/null
@@ -1,62 +0,0 @@
-"""Exhibit a bug: RequestChannel D-Bus timeout when requesting a group channel
-when the roster wasn't received yet"""
-
-# must come before the twisted imports due to side-effects
-from gabbletest import go, make_result_iq
-from servicetest import call_async, lazy, match, tp_name_prefix, unwrap, Event
-
-from twisted.internet.protocol import Factory, Protocol
-from twisted.words.protocols.jabber.client import IQ
-from twisted.words.xish import domish, xpath
-from twisted.internet import reactor
-
- at lazy
- at match('dbus-signal', signal='StatusChanged', args=[0, 1])
-def expect_connected(event, data):
- return True
-
- at match('stream-iq', query_ns='jabber:iq:roster')
-def expect_roster_iq(event, data):
- event.stanza['type'] = 'result'
-
- # handle type is Handle_Type_Group
- call_async(data['test'], data['conn_iface'], 'RequestHandles', 4,
- ['test'])
-
- # We'll send the reply *after* our channel request
- data['roster_reply'] = event.stanza
-
- return True
-
- at match('dbus-return', method='RequestHandles')
-def expect_request_handles_return(event, data):
- handles = event.value[0]
- data['group_test_handle'] = handles[0]
-
- call_async(data['test'], data['conn_iface'], 'RequestChannel',
- 'org.freedesktop.Telepathy.Channel.Type.ContactList', 4, handles[0], True)
-
- data['stream'].send(data['roster_reply'])
-
- return True
-
- at lazy
- at match('dbus-return', method='RequestChannel')
-def expect_request_channel_return(event, data):
- return True
-
-
- at match('dbus-signal', signal='NewChannel')
-def expect_new_channel(event, data):
- if event.args[1] != 'org.freedesktop.Telepathy.Channel.Type.ContactList':
- return False
-
- if event.args[2] != 4: # handle type is not Handle_Type_Group
- return False
-
- assert event.args[3] == data['group_test_handle']
-
- return True
-
-if __name__ == '__main__':
- go()
--
1.5.6.5
More information about the Telepathy-commits
mailing list