From 0bde9e5973fe306e428ec604d85aaafb0c1a9bd5 Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Tue, 20 Sep 2011 11:29:08 +0100 Subject: Add a connectivity test This test does not run if neither NM nor ConnMan support is available. It also only runs against the test-specific MC daemon, since it depends on a backdoor method for synchronisation. --- tests/twisted/Makefile.am | 12 +++ tests/twisted/account-manager/connectivity.py | 107 ++++++++++++++++++++++++++ 2 files changed, 119 insertions(+) create mode 100644 tests/twisted/account-manager/connectivity.py diff --git a/tests/twisted/Makefile.am b/tests/twisted/Makefile.am index bc3dc09d..5832e53e 100644 --- a/tests/twisted/Makefile.am +++ b/tests/twisted/Makefile.am @@ -79,6 +79,7 @@ endif # account-storage/*.py need their own instances. TWISTED_SPECIAL_BUILD_TESTS = \ account-manager/auto-away.py \ + account-manager/connectivity.py \ account-manager/hidden.py \ account-storage/default-keyring-storage.py \ account-storage/diverted-storage.py @@ -103,9 +104,20 @@ else HAVE_MCE_PYBOOL = False endif +if HAVE_NM +HAVE_CONNECTIVITY_PYBOOL = True +else +if HAVE_CONNMAN +HAVE_CONNECTIVITY_PYBOOL = True +else +HAVE_CONNECTIVITY_PYBOOL = False +endif +endif + config.py: Makefile $(AM_V_GEN) { \ echo "HAVE_MCE = $(HAVE_MCE_PYBOOL)"; \ + echo "HAVE_CONNECTIVITY = $(HAVE_CONNECTIVITY_PYBOOL)"; \ } > $@ BUILT_SOURCES = config.py diff --git a/tests/twisted/account-manager/connectivity.py b/tests/twisted/account-manager/connectivity.py new file mode 100644 index 00000000..5b9953d6 --- /dev/null +++ b/tests/twisted/account-manager/connectivity.py @@ -0,0 +1,107 @@ +# vim: set fileencoding=utf-8 : +# Copyright © 2011 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.service + +from servicetest import ( + EventPattern, call_async, sync_dbus, +) +from mctest import ( + exec_test, create_fakecm_account, expect_fakecm_connection, + SimulatedConnection, +) +import constants as cs + +import config + +if not config.HAVE_CONNECTIVITY: + print "NOTE: built without ConnMan or NM support" + raise SystemExit(77) + +def test(q, bus, mc): + params = dbus.Dictionary( + {"account": "yum yum network manager", + "password": "boo boo connman (although your API *is* simpler)", + }, signature='sv') + (cm_name_ref, account) = create_fakecm_account(q, bus, mc, params) + + # While we're not connected to the internet, RequestConnection should not + # be called. + request_connection_event = [ + EventPattern('dbus-method-call', method='RequestConnection'), + ] + q.forbid_events(request_connection_event) + + account.Properties.Set(cs.ACCOUNT, 'RequestedPresence', + (dbus.UInt32(cs.PRESENCE_TYPE_BUSY), 'busy', 'hlaghalgh')) + + # Turn the account on, re-request an online presence, and even tell it to + # connect automatically, to check that none of these make it sign in. + call_async(q, account.Properties, 'Set', cs.ACCOUNT, 'Enabled', True) + q.expect('dbus-return', method='Set') + call_async(q, account.Properties, 'Set', cs.ACCOUNT, 'RequestedPresence', + (dbus.UInt32(cs.PRESENCE_TYPE_BUSY), 'busy', 'hlaghalgh')) + q.expect('dbus-return', method='Set') + call_async(q, account.Properties, 'Set', cs.ACCOUNT, 'ConnectAutomatically', + True) + q.expect('dbus-return', method='Set') + + sync_dbus(bus, q, mc) + q.unforbid_events(request_connection_event) + + # Okay, I'm satisfied. Turn the network on. + mc.connectivity.go_online() + + expect_fakecm_connection(q, bus, mc, account, params) + + # If we turn the network off, the connection should be banished. + mc.connectivity.go_offline() + q.expect('dbus-method-call', method='Disconnect') + + # When we turn the network back on, MC should try to sign us back on. + mc.connectivity.go_online() + e = q.expect('dbus-method-call', method='RequestConnection') + + # But if we get disconnected before RequestConnection returns, MC should + # clean up the new connection when it does, rather than trying to sign it + # in. + connect_event = [ EventPattern('dbus-method-call', method='Connect'), ] + q.forbid_events(connect_event) + + mc.connectivity.go_offline() + # Make sure that MC has noticed that the network connection has gone away. + # + # We cannot simply use sync_dbus here, because nm-glib reports property + # changes in an idle (presumably to batch them all together). This is fine + # and all that, but means we have to find a way to make sure MC has flushed + # its idle queue to avoid this test being racy. (This isn't just + # theoretical: this test failed about once per five runs when it used sync_dbus.) + # + # The test-specific version of MC implements the 'BillyIdle' method, which + # returns from a low-priority idle. + mc.BillyIdle(dbus_interface='org.freedesktop.Telepathy.MissionControl5.RegressionTests') + + conn = SimulatedConnection(q, bus, 'fakecm', 'fakeprotocol', + account.object_path.split('/')[-1], 'myself') + q.dbus_return(e.message, conn.bus_name, conn.object_path, signature='so') + + q.expect('dbus-method-call', method='Disconnect') + +if __name__ == '__main__': + exec_test(test, initially_online=False) -- cgit v1.2.1