diff options
author | Will Thompson <will.thompson@collabora.co.uk> | 2011-02-24 17:56:35 +0000 |
---|---|---|
committer | Will Thompson <will.thompson@collabora.co.uk> | 2011-03-01 15:13:18 +0000 |
commit | 41dec7ea5438f44068318fb4c69f28e5a13fa241 (patch) | |
tree | b8e640f4522636670cd5ce095076b014a7d999d3 /tests | |
parent | 6933fb3526029c61c3078177f8bc3cd3bb9e0358 (diff) |
Be more robust against cataclysmic test failures
Previously, if MC never claimed its bus names (because it was crashing
on startup, for instance), the exception in the test initialization code
wasn't caught. This means nothing would ever quit the Twisted mainloop,
and the (failed) test would sit there forever.
This patch ensures that the test exits uncleanly if this happens.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/twisted/mctest.py | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/tests/twisted/mctest.py b/tests/twisted/mctest.py index fee227f3..8a37e914 100644 --- a/tests/twisted/mctest.py +++ b/tests/twisted/mctest.py @@ -66,6 +66,16 @@ def install_colourer(): sys.stdout = Colourer(sys.stdout, patterns) return sys.stdout +def wait_for_name(queue, bus, name): + if not bus.name_has_owner(name): + queue.expect('dbus-signal', signal='NameOwnerChanged', + predicate=lambda e: e.args[0] == name and e.args[2]) + +def wait_for_mc(queue, bus, params): + mc = make_mc(bus, queue.append, params) + wait_for_name(queue, bus, cs.AM) + wait_for_name(queue, bus, cs.CD) + return mc def exec_test_deferred (fun, params, protocol=None, timeout=None, preload_mc=True): @@ -81,23 +91,17 @@ def exec_test_deferred (fun, params, protocol=None, timeout=None, bus = dbus.SessionBus() queue.attach_to_bus(bus) - if preload_mc: - mc = make_mc(bus, queue.append, params) - - try: - bus.get_name_owner(cs.AM) - except dbus.DBusException, e: - queue.expect('dbus-signal', signal='NameOwnerChanged', - predicate=lambda e: e.args[0] == cs.AM and e.args[2]) + error = None + if preload_mc: try: - bus.get_name_owner(cs.CD) - except dbus.DBusException, e: - queue.expect('dbus-signal', signal='NameOwnerChanged', - predicate=lambda e: e.args[0] == cs.CD and e.args[2]) + mc = wait_for_mc(queue, bus, params) + except Exception, e: + import traceback + traceback.print_exc() + os._exit(1) else: mc = None - error = None try: fun(queue, bus, mc) |