Skip to content

Commit 424162b

Browse files
fix: replace sleep with asyncio.Event in cancellation test
The timing-based sleep(0.01) synchronization could be flaky on slow CI. Now uses an asyncio.Event for deterministic task coordination. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 85269e2 commit 424162b

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

tests/test_pool.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,15 @@ async def test_cancellation_does_not_leak_connection(self) -> None:
101101
await pool.initialize()
102102

103103
initial_size = pool._size
104+
acquired = asyncio.Event()
104105

105106
async def hold_connection():
106107
async with pool.acquire() as conn:
108+
acquired.set()
107109
await asyncio.sleep(10) # Hold forever
108110

109111
task = asyncio.create_task(hold_connection())
110-
await asyncio.sleep(0.01) # Let task acquire
112+
await acquired.wait() # Deterministic: wait until connection is acquired
111113

112114
task.cancel()
113115
try:

0 commit comments

Comments
 (0)