test-dbus.py: remove timeout before entering cleanup

When an exception occurred inside TestDBusSession.testSecondSession,
the timeout wasn't removed and would fire sometime later. If the
original problem was "server died", then the timeout code would
try to detach and cause another exception, which then stopped
the whole test-dbus.py run because it triggered outside of a test's
catch block.

This patch solves this by always removing the timeout in a "finally"
clause.
This commit is contained in:
Patrick Ohly 2010-05-27 17:31:35 +02:00
parent 912c52e370
commit 6aff1e8988
1 changed files with 18 additions and 16 deletions

View File

@ -926,22 +926,24 @@ class TestDBusSession(unittest.TestCase, DBusUtil):
def callback():
callback_called[1] = "callback()"
self.session.Detach()
t1 = self.addTimeout(2, callback)
# session 1 done
loop.run()
self.failUnless(callback_called)
# session 2 ready and idle
loop.run()
loop.run()
expected = ["session " + self.sessionpath + " done",
"session " + sessionpath + " idle",
"session " + sessionpath + " ready"]
expected.sort()
DBusUtil.quit_events.sort()
self.failUnlessEqual(DBusUtil.quit_events, expected)
status, error, sources = session.GetStatus(utf8_strings=True)
self.failUnlessEqual(status, "idle")
self.removeTimeout(t1)
try:
t1 = self.addTimeout(2, callback)
# session 1 done
loop.run()
self.failUnless(callback_called)
# session 2 ready and idle
loop.run()
loop.run()
expected = ["session " + self.sessionpath + " done",
"session " + sessionpath + " idle",
"session " + sessionpath + " ready"]
expected.sort()
DBusUtil.quit_events.sort()
self.failUnlessEqual(DBusUtil.quit_events, expected)
status, error, sources = session.GetStatus(utf8_strings=True)
self.failUnlessEqual(status, "idle")
finally:
self.removeTimeout(t1)
class TestSessionAPIsEmptyName(unittest.TestCase, DBusUtil):
"""Test session APIs that work with an empty server name. Thus, all of session APIs which