3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-20 12:39:25 +01:00

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.
This commit is contained in:
James Prestwood 2021-02-04 16:06:03 -08:00 committed by Denis Kenzior
parent c026337792
commit 4b07280319

View File

@ -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):