D-Bus testing: default timeout -> infinite
It is highly annoying that D-Bus method calls (synchronous and asynchronous!) time out fairly quickly (a few minutes) when doing interactive debugging of syncevo-dbus-server. Traditionally, every single method call had to be made with timeout=<some high value>, which made the test code unnecessarily larger and often was forgotten. Now all method calls via the session bus connection are done with a high timeout if none was set by the caller. This is achieved by wrapping the default (internal?) method send methods on the bus object with versions which add that timeout. This should be safe, because these methods are part of the public D-Bus Python API.
This commit is contained in:
parent
83c515b950
commit
3458d61164
|
@ -142,6 +142,28 @@ atexit.register(os.kill, child, 9)
|
|||
bus = dbus.SessionBus()
|
||||
loop = gobject.MainLoop()
|
||||
|
||||
# Override the default Connection.send_message_with_reply() with a
|
||||
# version that uses a very large timeout. That saves us the trouble of
|
||||
# putting a timeout=<large value> whenever we call a D-Bus method. We
|
||||
# don't want the default timeout because we may be debugging
|
||||
# interactively, which can slow down call processing longer than the
|
||||
# default timeout.
|
||||
#
|
||||
# See http://dbus.freedesktop.org/doc/dbus-python/api/dbus.connection-pysrc.html#Connection.call_async
|
||||
#
|
||||
real_send_message_with_reply = bus.send_message_with_reply
|
||||
real_send_message_with_reply_and_block = bus.send_message_with_reply_and_block
|
||||
def my_send_message_with_reply(msg, reply_handler, timeout_s=-1, require_main_loop=False):
|
||||
if timeout_s == -1:
|
||||
timeout_s = 100000
|
||||
return real_send_message_with_reply(msg, reply_handler, timeout_s, require_main_loop=require_main_loop)
|
||||
bus.send_message_with_reply = my_send_message_with_reply
|
||||
def my_send_message_with_reply_and_block(msg, timeout_s):
|
||||
if timeout_s == -1:
|
||||
timeout_s = 100000
|
||||
return real_send_message_with_reply_and_block(msg, timeout_s)
|
||||
bus.send_message_with_reply_and_block = my_send_message_with_reply_and_block
|
||||
|
||||
# log to .dbus.log of a test and to stdout, if running a debugger
|
||||
class Logging(dbus.service.Object):
|
||||
def __init__(self):
|
||||
|
|
Loading…
Reference in New Issue