From 4b07280319ea8189e14915d3bf40833da360581b Mon Sep 17 00:00:00 2001 From: James Prestwood Date: Thu, 4 Feb 2021 16:06:03 -0800 Subject: [PATCH] auto-t: fix wait_for_object_condition to work with any object After recent changes fixing wait_for_object_condition it was accidentally made to only work with classes, not other types of objects. Instead create a minimal class to hold _wait_timed_out so it doesnt rely on 'obj' holding the boolean. --- autotests/util/iwd.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/autotests/util/iwd.py b/autotests/util/iwd.py index 4fa26517..6b153ea7 100755 --- a/autotests/util/iwd.py +++ b/autotests/util/iwd.py @@ -1009,23 +1009,26 @@ class IWD(AsyncOpAbstract): @staticmethod def _wait_for_object_condition(obj, condition_str, max_wait = 50): - obj._wait_timed_out = False + class TimeoutData: + _wait_timed_out = False - def wait_timeout_cb(): - obj._wait_timed_out = True + data = TimeoutData() + + def wait_timeout_cb(data): + data._wait_timed_out = True return False try: - timeout = GLib.timeout_add_seconds(max_wait, wait_timeout_cb) + timeout = GLib.timeout_add_seconds(max_wait, wait_timeout_cb, data) context = ctx.mainloop.get_context() while not eval(condition_str): context.iteration(may_block=True) - if obj._wait_timed_out and ctx.args.gdb == None: + if data._wait_timed_out and ctx.args.gdb == None: raise TimeoutError('[' + condition_str + ']'\ ' condition was not met in '\ + str(max_wait) + ' sec') finally: - if not obj._wait_timed_out: + if not data._wait_timed_out: GLib.source_remove(timeout) def wait_for_object_condition(self, *args, **kwargs):