[gnome-bluetooth/wip/hadess/tests-fix-timeout] tests: Fix wait_for_condition()




commit 9fb72c027f9119e6992771e4ce1f0a33c80d3e7c
Author: Bastien Nocera <hadess hadess net>
Date:   Wed Feb 23 13:20:43 2022 +0100

    tests: Fix wait_for_condition()
    
    Correctly loop for "timeout" seconds instead of returning after the
    first iteration of the mainloop.

 tests/integration-test.py | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
---
diff --git a/tests/integration-test.py b/tests/integration-test.py
index 306cc0c0..99d97def 100755
--- a/tests/integration-test.py
+++ b/tests/integration-test.py
@@ -79,11 +79,18 @@ class OopTests(dbusmock.DBusTestCase):
 
     def wait_for_condition(self, condition, timeout=5):
         ctx = GLib.main_context_default()
+        timeout = timeout * 1000
+        interval = 100
         timed_out = False
         def timeout_cb():
             nonlocal timed_out
-            timed_out = True
-        GLib.timeout_add(100, timeout_cb)
+            nonlocal interval
+            timeout = timeout - interval
+            if timeout <= 0:
+                timed_out = True
+                return False
+            return True
+        GLib.timeout_add(interval, timeout_cb)
         while not condition() and not timed_out:
           ctx.iteration(True)
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]