D-Bus testing: better output when a test times out

When a test is stuck in a loop.run() and times out before the expected
event arrives, then the logged message wasn't very informative (just a
generic "timed out"). Now the error message includes a stack backtrace
(useful to find out where the test was waiting, and thus for what) and
the list of all events received so far (useful to determine which one
is missing).
This commit is contained in:
Patrick Ohly 2012-03-30 07:37:17 +00:00
parent 57cc7a33aa
commit 06d42e3b11
1 changed files with 4 additions and 3 deletions

View File

@ -35,6 +35,7 @@ from dbus.mainloop.glib import DBusGMainLoop
import dbus.service
import gobject
import sys
import traceback
import re
import atexit
@ -510,7 +511,7 @@ class DBusUtil(Timeout):
timeout_handle = None
if timeout and not debugger:
def timedout():
error = "%s timed out after %d seconds" % (self.id(), timeout)
error = "%s timed out after %d seconds, current quit events: %s" % (self.id(), timeout, self.quit_events)
if Timeout.debugTimeout:
print error
raise Exception(error)
@ -518,11 +519,11 @@ class DBusUtil(Timeout):
try:
self.running = True
unittest.TestCase.run(self, result)
except KeyboardInterrupt:
except KeyboardInterrupt, ex:
# somehow this happens when timedout() above raises the exception
# while inside glib main loop
result.errors.append((self,
"interrupted by timeout or CTRL-C or Python signal handler problem"))
"interrupted by timeout (%d seconds, current quit events: %s) or CTRL-C or Python signal handler problem, exception is: %s" % (timeout, self.quit_events, traceback.format_exc())))
self.running = False
self.removeTimeout(timeout_handle)
if debugger: