From 3ead5fadd75a2bfe4a04bd000908eac0e52b3856 Mon Sep 17 00:00:00 2001 From: catborise Date: Sun, 8 Nov 2026 20:51:02 +0300 Subject: [PATCH] test(connection): a close during the lookup returns the connection it checked The test fired the close callback at the 1st, 2nd or 3rd isAlive call of a lookup, but a lookup calls isAlive once: two of its three cases closed nothing. It also took a libvirtError for a result, as it only asserted that the result was not None. It now runs the one interleaving there is and asserts that the lookup returns the connection it checked. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea --- vrtManager/tests/test_connection_threads.py | 34 +++++++++------------ 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/vrtManager/tests/test_connection_threads.py b/vrtManager/tests/test_connection_threads.py index 77d51999..c4173e9a 100644 --- a/vrtManager/tests/test_connection_threads.py +++ b/vrtManager/tests/test_connection_threads.py @@ -85,27 +85,23 @@ class ConnectionThreadsTestCase(unittest.TestCase): def test_a_close_during_the_lookup_never_returns_none(self): """The close callback runs on the event loop thread, at any moment of - another thread's get_connection.""" - for nth in range(1, 4): - with self.subTest(nth=nth): - self.manager = wvmConnectionManager() - conn = alive_connection() - self.release.set() - with self.open_auth(conn): - self.assertIs(self.get(), conn) - entry = self.entries()[0] - calls = [] + another thread's get_connection: here while it checks the connection.""" + conn = alive_connection() + self.release.set() + with self.open_auth(conn): + self.assertIs(self.get(), conn) + entry = self.entries()[0] - def is_alive(): - calls.append(1) - if len(calls) == nth and not entry.connection_state_lock.locked(): - entry._wvmConnection__connection_close_callback(conn, 2) - return 1 + def is_alive(): + entry._wvmConnection__connection_close_callback(conn, 2) + return 1 - conn.isAlive.side_effect = is_alive - with self.open_auth(alive_connection()): - result = self.get() - self.assertIsNotNone(result) + conn.isAlive.side_effect = is_alive + reopened = alive_connection() + with self.open_auth(reopened): + result = self.get() + self.assertIsNone(entry.connection) # the close came during the lookup + self.assertIs(result, conn) # the connection it checked, not None or an error if __name__ == "__main__":