[gnome-bluetooth/wip/hadess/bluetooth-off-turn-off] tests: Add a timeout in wait_for_condition()



commit 39ef9cb0719674e8a5bbab66d8796fa617348a00
Author: Bastien Nocera <hadess hadess net>
Date:   Wed Dec 1 11:15:58 2021 +0100

    tests: Add a timeout in wait_for_condition()

 tests/integration-test | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
---
diff --git a/tests/integration-test b/tests/integration-test
index a71fcecd..dee4cb77 100755
--- a/tests/integration-test
+++ b/tests/integration-test
@@ -73,9 +73,14 @@ class OopTests(dbusmock.DBusTestCase):
         GLib.timeout_add_seconds(1, ml.quit)
         ml.run()
 
-    def wait_for_condition(self, condition):
+    def wait_for_condition(self, condition, timeout=5):
         ctx = GLib.main_context_default()
-        while not condition():
+        timed_out = False
+        def timeout_cb():
+            nonlocal timed_out
+            timed_out = True
+        GLib.timeout_add_seconds(1, timeout_cb)
+        while not condition() and not timed_out:
           ctx.iteration(True)
 
     def test_no_adapters(self):


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