From 36926af2665bf9e7cf2b97313e1765a0182ce3eb Mon Sep 17 00:00:00 2001 From: teknium1 <127238744+teknium1@users.noreply.github.com> Date: Sat, 25 Jul 2026 22:43:53 -0700 Subject: [PATCH] test(sessions): prove the connector reached the lock before asserting blocked Closes the last false-pass window @helix4u flagged on #71779. He explicitly said not to hold the PR for it; it is two lines, so worth doing rather than leaving a known-soft assertion in a concurrency test. connection_opened.wait(1.0) proved the connection had not opened, but not that the connector thread had actually reached connect_tracked() -- an unscheduled thread produces the same observation. The connector now sets connect_attempted immediately before the blocking call, and the test waits on that first, so "still blocked" means blocked at the lock rather than not yet started. 15/15 stable at ~1.1s. Removed-lock sabotage still fails. --- tests/hermes_cli/test_session_recovery.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/hermes_cli/test_session_recovery.py b/tests/hermes_cli/test_session_recovery.py index cb6f9c05ef31..612f13abf16f 100644 --- a/tests/hermes_cli/test_session_recovery.py +++ b/tests/hermes_cli/test_session_recovery.py @@ -315,6 +315,7 @@ def test_snapshot_blocks_connections_opened_during_the_copy( inside_copy = threading.Event() release_copy = threading.Event() + connect_attempted = threading.Event() connection_opened = threading.Event() errors: list[str] = [] real_copy2 = recovery_module.shutil.copy2 @@ -333,6 +334,10 @@ def test_snapshot_blocks_connections_opened_during_the_copy( errors.append(f"copy failed: {exc}") def do_connect(): + # Signal immediately before the blocking call so a timed "still + # blocked" assertion cannot pass merely because this thread had not + # been scheduled yet. + connect_attempted.set() try: conn = connect_tracked(source, isolation_level=None, timeout=30.0) connection_opened.set() @@ -348,7 +353,9 @@ def test_snapshot_blocks_connections_opened_during_the_copy( assert inside_copy.wait(30), "copy never reached the patched operation" connector.start() - # While the copy holds the lifecycle lock the connection must not open. + assert connect_attempted.wait(30), "connector thread never started" + # The connector is at the lock. While the copy holds it, the + # connection must not open. assert not connection_opened.wait(1.0), ( "connect_tracked() completed while raw copy descriptors were open " "— the guard is not holding the lifecycle lock across the copy"