[telepathy-mission-control/master] Add a regression test for losing channels during approval
Simon McVittie
simon.mcvittie at collabora.co.uk
Mon Apr 20 07:29:08 PDT 2009
---
test/twisted/Makefile.am | 3 +-
test/twisted/constants.py | 1 +
test/twisted/dispatcher/lose-text.py | 191 ++++++++++++++++++++++++++++++++++
3 files changed, 194 insertions(+), 1 deletions(-)
create mode 100644 test/twisted/dispatcher/lose-text.py
diff --git a/test/twisted/Makefile.am b/test/twisted/Makefile.am
index 96b70cc..19e0477 100644
--- a/test/twisted/Makefile.am
+++ b/test/twisted/Makefile.am
@@ -10,9 +10,10 @@ TWISTED_BASIC_TESTS = \
dispatcher/already-has-channel.py \
dispatcher/cancel.py \
dispatcher/create-text.py \
+ dispatcher/dispatch-text.py \
dispatcher/exploding-bundles.py \
dispatcher/fdo-21034.py \
- dispatcher/dispatch-text.py \
+ dispatcher/lose-text.py \
do-nothing.py \
test-account.py \
test-connect.py
diff --git a/test/twisted/constants.py b/test/twisted/constants.py
index 61ec974..6408bde 100644
--- a/test/twisted/constants.py
+++ b/test/twisted/constants.py
@@ -65,6 +65,7 @@ NOT_IMPLEMENTED = ERROR + '.NotImplemented'
NOT_AVAILABLE = ERROR + '.NotAvailable'
PERMISSION_DENIED = ERROR + '.PermissionDenied'
CANCELLED = ERROR + '.Cancelled'
+NOT_YOURS = ERROR + '.NotYours'
TUBE_PARAMETERS = CHANNEL_IFACE_TUBE + '.Parameters'
TUBE_STATE = CHANNEL_IFACE_TUBE + '.State'
diff --git a/test/twisted/dispatcher/lose-text.py b/test/twisted/dispatcher/lose-text.py
new file mode 100644
index 0000000..d9bc1b3
--- /dev/null
+++ b/test/twisted/dispatcher/lose-text.py
@@ -0,0 +1,191 @@
+"""Regression test for losing a channel while AddDispatchOperation is being
+called.
+"""
+
+import dbus
+import dbus.service
+
+from servicetest import EventPattern, tp_name_prefix, tp_path_prefix, \
+ call_async
+from mctest import exec_test, SimulatedConnection, SimulatedClient, \
+ create_fakecm_account, enable_fakecm_account, SimulatedChannel
+import constants as cs
+
+def test(q, bus, mc):
+ params = dbus.Dictionary({"account": "someguy at example.com",
+ "password": "secrecy"}, signature='sv')
+ cm_name_ref, account = create_fakecm_account(q, bus, mc, params)
+ conn = enable_fakecm_account(q, bus, mc, account, params)
+
+ text_fixed_properties = dbus.Dictionary({
+ cs.CHANNEL + '.TargetHandleType': cs.HT_CONTACT,
+ cs.CHANNEL + '.ChannelType': cs.CHANNEL_TYPE_TEXT,
+ }, signature='sv')
+
+ # Two clients want to observe, approve and handle channels
+ empathy = SimulatedClient(q, bus, 'Empathy',
+ observe=[text_fixed_properties], approve=[text_fixed_properties],
+ handle=[text_fixed_properties], bypass_approval=False)
+ kopete = SimulatedClient(q, bus, 'Kopete',
+ observe=[text_fixed_properties], approve=[text_fixed_properties],
+ handle=[text_fixed_properties], bypass_approval=False)
+
+ # wait for MC to download the properties
+ q.expect_many(
+ EventPattern('dbus-method-call',
+ interface=cs.PROPERTIES_IFACE, method='Get',
+ args=[cs.CLIENT, 'Interfaces'],
+ path=empathy.object_path),
+ EventPattern('dbus-method-call',
+ interface=cs.PROPERTIES_IFACE, method='Get',
+ args=[cs.APPROVER, 'ApproverChannelFilter'],
+ path=empathy.object_path),
+ EventPattern('dbus-method-call',
+ interface=cs.PROPERTIES_IFACE, method='Get',
+ args=[cs.HANDLER, 'HandlerChannelFilter'],
+ path=empathy.object_path),
+ EventPattern('dbus-method-call',
+ interface=cs.PROPERTIES_IFACE, method='Get',
+ args=[cs.OBSERVER, 'ObserverChannelFilter'],
+ path=empathy.object_path),
+
+ EventPattern('dbus-method-call',
+ interface=cs.PROPERTIES_IFACE, method='Get',
+ args=[cs.CLIENT, 'Interfaces'],
+ path=kopete.object_path),
+ EventPattern('dbus-method-call',
+ interface=cs.PROPERTIES_IFACE, method='Get',
+ args=[cs.APPROVER, 'ApproverChannelFilter'],
+ path=kopete.object_path),
+ EventPattern('dbus-method-call',
+ interface=cs.PROPERTIES_IFACE, method='Get',
+ args=[cs.HANDLER, 'HandlerChannelFilter'],
+ path=kopete.object_path),
+ EventPattern('dbus-method-call',
+ interface=cs.PROPERTIES_IFACE, method='Get',
+ args=[cs.OBSERVER, 'ObserverChannelFilter'],
+ path=kopete.object_path),
+ )
+
+ # subscribe to the OperationList interface (MC assumes that until this
+ # property has been retrieved once, nobody cares)
+
+ cd = bus.get_object(cs.CD_BUS_NAME, cs.CD_PATH)
+ cd_props = dbus.Interface(cd, cs.PROPERTIES_IFACE)
+ assert cd_props.Get(cs.CD_IFACE_OP_LIST, 'DispatchOperations') == []
+
+ channel_properties = dbus.Dictionary(text_fixed_properties,
+ signature='sv')
+ channel_properties[cs.CHANNEL + '.TargetID'] = 'juliet'
+ channel_properties[cs.CHANNEL + '.TargetHandle'] = \
+ conn.ensure_handle(cs.HT_CONTACT, 'juliet')
+ channel_properties[cs.CHANNEL + '.InitiatorID'] = 'juliet'
+ channel_properties[cs.CHANNEL + '.InitiatorHandle'] = \
+ conn.ensure_handle(cs.HT_CONTACT, 'juliet')
+ channel_properties[cs.CHANNEL + '.Requested'] = False
+ channel_properties[cs.CHANNEL + '.Interfaces'] = dbus.Array(signature='s')
+
+ chan = SimulatedChannel(conn, channel_properties)
+ chan.announce()
+
+ # A channel dispatch operation is created
+
+ e = q.expect('dbus-signal',
+ path=cs.CD_PATH,
+ interface=cs.CD_IFACE_OP_LIST,
+ signal='NewDispatchOperation')
+
+ cdo_path = e.args[0]
+ cdo_properties = e.args[1]
+
+ assert cdo_properties[cs.CDO + '.Account'] == account.object_path
+ assert cdo_properties[cs.CDO + '.Connection'] == conn.object_path
+ assert cs.CDO + '.Interfaces' in cdo_properties
+
+ handlers = cdo_properties[cs.CDO + '.PossibleHandlers'][:]
+ handlers.sort()
+ assert handlers == [cs.tp_name_prefix + '.Client.Empathy',
+ cs.tp_name_prefix + '.Client.Kopete'], handlers
+
+ assert cdo_properties[cs.CDO + '.Channels'] == [(chan.object_path,
+ channel_properties)]
+
+ assert cs.CD_IFACE_OP_LIST in cd_props.Get(cs.CD, 'Interfaces')
+ assert cd_props.Get(cs.CD_IFACE_OP_LIST, 'DispatchOperations') ==\
+ [(cdo_path, cdo_properties)]
+
+ cdo = bus.get_object(cs.CD_BUS_NAME, cdo_path)
+ cdo_iface = dbus.Interface(cdo, cs.CDO)
+
+ # Both Observers are told about the new channel
+
+ e, k = q.expect_many(
+ EventPattern('dbus-method-call',
+ path=empathy.object_path,
+ interface=cs.OBSERVER, method='ObserveChannels',
+ handled=False),
+ EventPattern('dbus-method-call',
+ path=kopete.object_path,
+ interface=cs.OBSERVER, method='ObserveChannels',
+ handled=False),
+ )
+ assert e.args[0] == account.object_path, e.args
+ assert e.args[1] == conn.object_path, e.args
+ channels = e.args[2]
+ assert len(channels) == 1, channels
+ assert channels[0][0] == chan.object_path, channels
+ assert channels[0][1] == channel_properties, channels
+
+ assert k.args == e.args
+
+ # Both Observers indicate that they are ready to proceed
+ q.dbus_return(k.message, signature='')
+ q.dbus_return(e.message, signature='')
+
+ # The Approvers are next
+
+ e, k = q.expect_many(
+ EventPattern('dbus-method-call',
+ path=empathy.object_path,
+ interface=cs.APPROVER, method='AddDispatchOperation',
+ handled=False),
+ EventPattern('dbus-method-call',
+ path=kopete.object_path,
+ interface=cs.APPROVER, method='AddDispatchOperation',
+ handled=False),
+ )
+
+ assert e.args == [cdo_path, cdo_properties]
+ assert k.args == [cdo_path, cdo_properties]
+
+ q.dbus_return(e.message, signature='')
+
+ # The channel closes before Kopete has said yes. As a result, MC isn't
+ # allowed to emit ChannelLost or Finished yet.
+ chan.close()
+
+ # Empathy wants to handle the channel, but is too late
+ call_async(q, cdo_iface, 'HandleWith',
+ cs.tp_name_prefix + '.Client.Empathy')
+ e = q.expect('dbus-error')
+ assert e.error.get_dbus_name() == cs.NOT_YOURS
+
+ # *Now* Kopete is happy...
+ q.dbus_return(k.message, signature='')
+
+ # ... and in response, the channel dispatch operation finishes
+
+ e = q.expect('dbus-signal', path=cdo_path, signal='ChannelLost')
+ assert e.args[0] == chan.object_path
+ # FIXME: e.args[1:] == [...Disconnected, 'Channel aborted'] which doesn't
+ # seem like the most appropriate thing for MC to do
+
+ q.expect('dbus-signal', path=cdo_path, signal='Finished')
+ q.expect('dbus-signal', path=cs.CD_PATH,
+ signal='DispatchOperationFinished', args=[cdo_path])
+
+ # Now there are no more active channel dispatch operations
+ assert cd_props.Get(cs.CD_IFACE_OP_LIST, 'DispatchOperations') == []
+
+if __name__ == '__main__':
+ exec_test(test, {})
--
1.5.6.5
More information about the telepathy-commits
mailing list