Skip to contentSkip to conversation

auto-t: fix wait_for_object_condition

PATCH Applied James Prestwood 2 participants 2 messages Jan 25, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 auto-t: fix wait_for_object_condition

After the re-write this was broken and not noticed until recently. The issue appeared to be that the GLib timeout callback retained no context of local variables. Previously _wait_timed_out was set as a class variable, but this was removed so multiple IWD instances could work. Without _wait_timed_out being a class variable the GLib timeout setting it had no effect on the wait loop.

To fix this we can set _wait_timed_out on the object being passed in. This is preserved in the GLib timeout callback and setting it gets honored in the wait loop.

---
 autotests/util/iwd.py | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
autotests/util/iwd.py +5 -4
index 9e653575..4fa26517 100755
@@ -1009,9 +1009,10 @@ class IWD(AsyncOpAbstract):
 
     @staticmethod
     def _wait_for_object_condition(obj, condition_str, max_wait = 50):
-        _wait_timed_out = False
+        obj._wait_timed_out = False
+
         def wait_timeout_cb():
-            _wait_timed_out = True
+            obj._wait_timed_out = True
             return False
 
         try:
@@ -1019,12 +1020,12 @@ class IWD(AsyncOpAbstract):
             context = ctx.mainloop.get_context()
             while not eval(condition_str):
                 context.iteration(may_block=True)
-                if _wait_timed_out and ctx.args.gdb == None:
+                if obj._wait_timed_out and ctx.args.gdb == None:
                     raise TimeoutError('[' + condition_str + ']'\
                                        ' condition was not met in '\
                                        + str(max_wait) + ' sec')
         finally:
-            if not _wait_timed_out:
+            if not obj._wait_timed_out:
                 GLib.source_remove(timeout)
 
     def wait_for_object_condition(self, *args, **kwargs):
Signature · 1 line
2.26.2
#1 lore raw

Hi James,

Quoted 8 lines · James Prestwood

After the re-write this was broken and not noticed until recently. The issue appeared to be that the GLib timeout callback retained no context of local variables. Previously _wait_timed_out was set as a class variable, but this was removed so multiple IWD instances could work. Without _wait_timed_out being a class variable the GLib timeout setting it had no effect on the wait loop.

Quoted 7 lines

To fix this we can set _wait_timed_out on the object being passed in. This is preserved in the GLib timeout callback and setting it gets honored in the wait loop.

---
  autotests/util/iwd.py | 9 +++++----
  1 file changed, 5 insertions(+), 4 deletions(-)

Applied, thanks.

Regards,
Denis