Skip to content

Commit 83995e4

Browse files
saurabh500Copilot
andcommitted
Add test for pool release overflow path (coverage lines 107-110)
Add test_pool_release_overflow_disconnects_outside_mutex to exercise the ConnectionPool::release() overflow path where a connection is returned to a pool that is already at max_size. This triggers the should_disconnect branch that disconnects outside the mutex. The disconnect-without-GIL path (connection.cpp lines 160-161) is a C++ destructor safety guard only reachable during interpreter shutdown when the last shared_ptr drops without the GIL held. This cannot be reliably exercised from a Python test since __del__/GC always holds the GIL. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 47c61cf commit 83995e4

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tests/test_009_pooling.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,35 @@ def try_overflow():
278278
c.close()
279279

280280

281+
def test_pool_release_overflow_disconnects_outside_mutex(conn_str):
282+
"""Test that releasing a connection when pool is full disconnects it correctly.
283+
284+
When a connection is returned to a pool that is already at max_size,
285+
the connection must be disconnected. This exercises the overflow path in
286+
ConnectionPool::release() (connection_pool.cpp lines 107-110) where
287+
should_disconnect is set and disconnect happens outside the mutex.
288+
"""
289+
pooling(max_size=1, idle_timeout=30)
290+
291+
# Open two connections — both succeed because the pool issues slots
292+
conn1 = connect(conn_str)
293+
conn2 = connect(conn_str)
294+
295+
# Close conn1 first — returned to the pool (pool now has 1 idle entry)
296+
conn1.close()
297+
298+
# Close conn2 — pool is full (1 idle already), so this connection
299+
# must be disconnected rather than pooled (overflow path).
300+
conn2.close()
301+
302+
# Verify the pool is still functional
303+
conn3 = connect(conn_str)
304+
cursor = conn3.cursor()
305+
cursor.execute("SELECT 1")
306+
assert cursor.fetchone()[0] == 1
307+
conn3.close()
308+
309+
281310
@pytest.mark.skip("Flaky test - idle timeout behavior needs investigation")
282311
def test_pool_idle_timeout_removes_connections(conn_str):
283312
"""Test that idle_timeout removes connections from the pool after the timeout."""

0 commit comments

Comments
 (0)