From 69ac3134a5b1465f35701581e224c0f87b26fb8e Mon Sep 17 00:00:00 2001 From: catborise Date: Thu, 8 Oct 2026 10:26:31 +0300 Subject: [PATCH] test(connection): wait for a released open instead of a fixed 0.1 s Two tests released a hanging open and slept 0.1 s before expecting its connection; on a slow CI runner the open had not published it yet and the stored timeout error came back. They now wait until the connection is published. --- vrtManager/test_connection.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/vrtManager/test_connection.py b/vrtManager/test_connection.py index e2e912a3..ad3115a1 100644 --- a/vrtManager/test_connection.py +++ b/vrtManager/test_connection.py @@ -101,6 +101,13 @@ class BoundedOpenTestCase(unittest.TestCase): except libvirt.libvirtError as err: return err, time.monotonic() - started + def wait_for_the_open(self, host="h"): + """Wait until the released open has published its connection.""" + entry = self.manager._search_connection(host, "u", "p", CONN_TCP) + deadline = time.monotonic() + 5 + while entry.connection is None and time.monotonic() < deadline: + time.sleep(0.01) + def test_a_hanging_open_is_given_up_after_the_timeout(self): with self.open_auth(alive_connection()): result, took = self.get() @@ -121,7 +128,7 @@ class BoundedOpenTestCase(unittest.TestCase): with self.open_auth(conn): self.get() self.release.set() - time.sleep(0.1) + self.wait_for_the_open() result, took = self.get() self.assertIs(result, conn) self.assertEqual(self.calls, 1) @@ -168,7 +175,7 @@ class BoundedOpenTestCase(unittest.TestCase): self.assertIsInstance(result, libvirt.libvirtError) self.assertLess(took, 0.1) self.release.set() # the host answers at last - time.sleep(0.1) + self.wait_for_the_open() result, _ = self.get() self.assertIs(result, conn) self.assertEqual(self.calls, 1)