[gnome-bluetooth/wip/hadess/remove-gtk-tree: 1/19] tests: Add a timeout in wait_for_condition()




commit 87fa6544a601bbcf8a66470a1cc767739756b6ce
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 1a196bb6..16b1360e 100755
--- a/tests/integration-test
+++ b/tests/integration-test
@@ -76,9 +76,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]