diff options
author | Patrick Ohly <patrick.ohly@intel.com> | 2013-05-02 01:05:58 -0700 |
---|---|---|
committer | Patrick Ohly <patrick.ohly@intel.com> | 2013-05-13 17:49:50 +0200 |
commit | 83a0c05763661d390fa61855b271bc990384798a (patch) | |
tree | 72f0ab9ff2e774c20cc2f46fd6164bffe0a1322a | |
parent | 60f7ccda876c06614b6a416dcb882f06701ee6bb (diff) |
D-Bus testing: implement removal of glib timeout
Use type checking to determine whether a timeout was done via
glib or signals. Without removal of a glib timeout, a periodic
timeout keeps firing in other tests.
-rwxr-xr-x | test/test-dbus.py | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/test/test-dbus.py b/test/test-dbus.py index 276e45df..ce86d047 100755 --- a/test/test-dbus.py +++ b/test/test-dbus.py @@ -252,9 +252,7 @@ class Timeout: DBusUtil.quit_events before calling loop.quit() caused a KeyboardInterrupt""" if have_glib and use_glib: - glib.timeout_add(delay_seconds, callback) - # TODO: implement removal of glib timeouts - return None + return glib.timeout_add(delay_seconds, callback) else: now = time.time() if cls.debugTimeout: @@ -268,13 +266,20 @@ class Timeout: def removeTimeout(cls, timeout): """Remove a timeout returned by a previous addTimeout call. None and timeouts which have already fired are acceptable.""" - try: - cls.alarms.remove(timeout) - except ValueError: + if timeout == None: pass + elif isinstance(timeout, tuple): + # non-glib case + try: + cls.alarms.remove(timeout) + except ValueError: + pass + else: + heapq.heapify(cls.alarms) + cls.__check_alarms() else: - heapq.heapify(cls.alarms) - cls.__check_alarms() + # glib timeout + glib.source_remove(timeout) @classmethod def __handler(cls, signum, stack): |