Skip to content

Commit 9aff556

Browse files
committed
Merge branch '5.0' into async
2 parents 8621bab + 8af8661 commit 9aff556

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

tests/unit/async_/io/test_neo4j_pool.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
# limitations under the License.
1717

1818

19-
from unittest.mock import Mock
20-
2119
import pytest
2220

2321
from neo4j import (
@@ -185,6 +183,37 @@ def break_connection():
185183
assert cx2 in pool.connections[cx2.addr]
186184

187185

186+
@mark_async_test
187+
async def test_does_not_close_stale_connections_in_use(opener):
188+
pool = AsyncNeo4jPool(
189+
opener, PoolConfig(), WorkspaceConfig(), ROUTER_ADDRESS
190+
)
191+
cx1 = await pool.acquire(READ_ACCESS, 30, "test_db", None)
192+
assert cx1 in pool.connections[cx1.addr]
193+
# simulate connection going stale (e.g. exceeding) while being in use
194+
cx1.stale.return_value = True
195+
cx2 = await pool.acquire(READ_ACCESS, 30, "test_db", None)
196+
await pool.release(cx2)
197+
cx1.close.assert_not_called()
198+
assert cx2 is not cx1
199+
assert cx2.addr == cx1.addr
200+
assert cx1 in pool.connections[cx1.addr]
201+
assert cx2 in pool.connections[cx2.addr]
202+
203+
await pool.release(cx1)
204+
# now that cx1 is back in the pool and still stale,
205+
# it should be closed when trying to acquire the next connection
206+
cx1.close.assert_not_called()
207+
208+
cx3 = await pool.acquire(READ_ACCESS, 30, "test_db", None)
209+
await pool.release(cx3)
210+
cx1.close.assert_called_once()
211+
assert cx2 is cx3
212+
assert cx3.addr == cx1.addr
213+
assert cx1 not in pool.connections[cx1.addr]
214+
assert cx3 in pool.connections[cx2.addr]
215+
216+
188217
@mark_async_test
189218
async def test_release_resets_connections(opener):
190219
pool = AsyncNeo4jPool(

0 commit comments

Comments
 (0)