[telepathy-mission-control/master] Add a test for the "probation" functionality of McdConnection
Simon McVittie
simon.mcvittie at collabora.co.uk
Thu Sep 17 10:16:14 PDT 2009
Because of the exponential backoff, this is fairly slow, so to enable it,
you have to set CHECK_TWISTED_SLOW to a non-empty value (or use
check-torture, which is slow already).
---
test/twisted/Makefile.am | 14 ++-
test/twisted/account-manager/server-drops-us.py | 128 +++++++++++++++++++++++
2 files changed, 140 insertions(+), 2 deletions(-)
create mode 100644 test/twisted/account-manager/server-drops-us.py
diff --git a/test/twisted/Makefile.am b/test/twisted/Makefile.am
index c0aad72..2abdd15 100644
--- a/test/twisted/Makefile.am
+++ b/test/twisted/Makefile.am
@@ -57,6 +57,9 @@ TWISTED_SPECIAL_BUILD_TESTS = \
account-manager/auto-away.py \
dispatcher/create-lowmem.py
+TWISTED_SLOW_TESTS = \
+ account-manager/server-drops-us.py
+
TWISTED_BASIC_TESTS += $(TWISTED_SPECIAL_BUILD_TESTS)
TWISTED_SEPARATE_TESTS = \
@@ -175,16 +178,23 @@ TORTURE_REPEATS = 100
_check-torture:
for i in `seq 1 $(TORTURE_REPEATS)`; do \
$(MAKE) check-TESTS \
- TESTS='$$(TWISTED_BASIC_TESTS)' \
+ TESTS='$$(TWISTED_BASIC_TESTS) $$(TWISTED_SLOW_TESTS)'\
TESTS_ENVIRONMENT='$$(COMBINED_TESTS_ENVIRONMENT)'; \
e=$$?; \
test z$$e = z0 || break; \
done
+CHECK_TWISTED_SLOW =
+
check-combined:
+ if test x$(CHECK_TWISTED_SLOW) = x; then \
+ extra_tests= ; \
+ else \
+ extra_tests=' $$(TWISTED_SLOW_TESTS)'; \
+ fi; \
env $(BASIC_TESTS_ENVIRONMENT) $(WITH_SESSION_BUS) \
$(MAKE) check-TESTS \
- TESTS='$$(TWISTED_BASIC_TESTS)' \
+ TESTS='$$(TWISTED_BASIC_TESTS)'"$${extra_tests}" \
TESTS_ENVIRONMENT='$$(COMBINED_TESTS_ENVIRONMENT)'
check-separate:
diff --git a/test/twisted/account-manager/server-drops-us.py b/test/twisted/account-manager/server-drops-us.py
new file mode 100644
index 0000000..b4db423
--- /dev/null
+++ b/test/twisted/account-manager/server-drops-us.py
@@ -0,0 +1,128 @@
+# Copyright (C) 2009 Nokia Corporation
+# Copyright (C) 2009 Collabora Ltd.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+# 02110-1301 USA
+
+import dbus
+import dbus
+import dbus.service
+
+from servicetest import EventPattern, tp_name_prefix, tp_path_prefix, \
+ call_async, sync_dbus, TimeoutError
+from mctest import exec_test, SimulatedConnection, create_fakecm_account,\
+ SimulatedChannel
+import constants as cs
+
+params = dbus.Dictionary({"account": "someguy at example.com",
+ "password": "secrecy"}, signature='sv')
+
+def test(q, bus, mc):
+ cm_name_ref = dbus.service.BusName(
+ tp_name_prefix + '.ConnectionManager.fakecm', bus=bus)
+
+ # Create an account
+ (cm_name_ref, account) = create_fakecm_account(q, bus, mc, params)
+
+ account_iface = dbus.Interface(account, cs.ACCOUNT)
+ account_props = dbus.Interface(account, cs.PROPERTIES_IFACE)
+
+ call_async(q, account, 'Set', cs.ACCOUNT, 'Enabled', False,
+ dbus_interface=cs.PROPERTIES_IFACE)
+ q.expect('dbus-return', method='Set')
+
+ # Enable the account
+ call_async(q, account, 'Set', cs.ACCOUNT, 'Enabled', True,
+ dbus_interface=cs.PROPERTIES_IFACE)
+
+ # Set online presence
+ presence = dbus.Struct((dbus.UInt32(cs.PRESENCE_TYPE_BUSY), 'busy',
+ 'Fixing MC bugs'), signature='uss')
+ call_async(q, account, 'Set', cs.ACCOUNT,
+ 'RequestedPresence', presence,
+ dbus_interface=cs.PROPERTIES_IFACE)
+
+ e = q.expect('dbus-method-call', method='RequestConnection',
+ args=['fakeprotocol', params],
+ destination=tp_name_prefix + '.ConnectionManager.fakecm',
+ path=tp_path_prefix + '/ConnectionManager/fakecm',
+ interface=tp_name_prefix + '.ConnectionManager',
+ handled=False)
+
+ conn = SimulatedConnection(q, bus, 'fakecm', 'fakeprotocol', '_',
+ 'myself', has_presence=True)
+
+ q.dbus_return(e.message, conn.bus_name, conn.object_path, signature='so')
+
+ # MC calls GetStatus (maybe) and then Connect
+
+ q.expect('dbus-method-call', method='Connect',
+ path=conn.object_path, handled=True)
+
+ # Connect succeeds
+ conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CONN_STATUS_REASON_NONE)
+
+ conn = drop_and_expect_reconnect(q, bus, conn)
+ conn = drop_and_expect_reconnect(q, bus, conn)
+ conn = drop_and_expect_reconnect(q, bus, conn)
+
+ forbidden = [EventPattern('dbus-method-call', method='RequestConnection')]
+ q.forbid_events(forbidden)
+
+ # Connection falls over for a miscellaneous reason
+ conn.StatusChanged(cs.CONN_STATUS_DISCONNECTED,
+ cs.CONN_STATUS_REASON_NETWORK_ERROR)
+ # Right, that's it, I'm giving up...
+
+ # This test can be considered to have succeeded if we don't
+ # RequestConnection again before the test fails due to timeout.
+ try:
+ q.expect('the end of the world')
+ except TimeoutError:
+ return
+ else:
+ raise AssertionError('An impossible event happened')
+
+def drop_and_expect_reconnect(q, bus, conn):
+ # Connection falls over for a miscellaneous reason
+ conn.StatusChanged(cs.CONN_STATUS_DISCONNECTED,
+ cs.CONN_STATUS_REASON_NETWORK_ERROR)
+
+ # MC reconnects
+
+ e = q.expect('dbus-method-call', method='RequestConnection',
+ args=['fakeprotocol', params],
+ destination=tp_name_prefix + '.ConnectionManager.fakecm',
+ path=tp_path_prefix + '/ConnectionManager/fakecm',
+ interface=tp_name_prefix + '.ConnectionManager',
+ handled=False)
+
+ conn = SimulatedConnection(q, bus, 'fakecm', 'fakeprotocol', '_',
+ 'myself', has_presence=True)
+
+ q.dbus_return(e.message, conn.bus_name, conn.object_path, signature='so')
+
+ # MC calls GetStatus (maybe) and then Connect
+
+ q.expect('dbus-method-call', method='Connect',
+ path=conn.object_path, handled=True)
+
+ # Connect succeeds
+ conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CONN_STATUS_REASON_NONE)
+
+ return conn
+
+if __name__ == '__main__':
+ exec_test(test, {})
--
1.5.6.5
More information about the telepathy-commits
mailing list