1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-11 12:46:49 +00:00

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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea
This commit is contained in:
catborise 2026-11-08 20:51:02 +03:00
parent b737b1f8f7
commit 3ead5fadd7

View file

@ -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__":