File tree Expand file tree Collapse file tree 4 files changed +44
-26
lines changed Expand file tree Collapse file tree 4 files changed +44
-26
lines changed Original file line number Diff line number Diff line change @@ -248,24 +248,14 @@ async def deactivate(self, address):
248
248
await conn .close ()
249
249
except OSError :
250
250
pass
251
- if not connections :
252
- await self .remove ( address )
251
+ if not self . connections [ address ] :
252
+ del self .connections [ address ]
253
253
254
254
def on_write_failure (self , address ):
255
255
raise WriteServiceUnavailable (
256
256
"No write service available for pool {}" .format (self )
257
257
)
258
258
259
- async def remove (self , address ):
260
- """ Remove an address from the connection pool, if present, closing
261
- all connections to that address.
262
- """
263
- async with self .lock :
264
- for connection in self .connections .pop (address , ()):
265
- try :
266
- await connection .close ()
267
- except OSError :
268
- pass
269
259
270
260
async def close (self ):
271
261
""" Close all connections and empty the pool.
@@ -274,7 +264,8 @@ async def close(self):
274
264
try :
275
265
async with self .lock :
276
266
for address in list (self .connections ):
277
- await self .remove (address )
267
+ for connection in self .connections .pop (address , ()):
268
+ await connection .close ()
278
269
except TypeError :
279
270
pass
280
271
Original file line number Diff line number Diff line change @@ -248,24 +248,14 @@ def deactivate(self, address):
248
248
conn .close ()
249
249
except OSError :
250
250
pass
251
- if not connections :
252
- self .remove ( address )
251
+ if not self . connections [ address ] :
252
+ del self .connections [ address ]
253
253
254
254
def on_write_failure (self , address ):
255
255
raise WriteServiceUnavailable (
256
256
"No write service available for pool {}" .format (self )
257
257
)
258
258
259
- def remove (self , address ):
260
- """ Remove an address from the connection pool, if present, closing
261
- all connections to that address.
262
- """
263
- with self .lock :
264
- for connection in self .connections .pop (address , ()):
265
- try :
266
- connection .close ()
267
- except OSError :
268
- pass
269
259
270
260
def close (self ):
271
261
""" Close all connections and empty the pool.
@@ -274,7 +264,8 @@ def close(self):
274
264
try :
275
265
with self .lock :
276
266
for address in list (self .connections ):
277
- self .remove (address )
267
+ for connection in self .connections .pop (address , ()):
268
+ connection .close ()
278
269
except TypeError :
279
270
pass
280
271
Original file line number Diff line number Diff line change 35
35
)
36
36
37
37
from ...._async_compat import mark_async_test
38
+ from ..._async_compat import (
39
+ AsyncMock ,
40
+ mark_async_test ,
41
+ )
38
42
from ..work import async_fake_connection_generator
39
43
40
44
@@ -384,3 +388,17 @@ def liveness_side_effect(*args, **kwargs):
384
388
cx3 .reset .assert_awaited_once ()
385
389
assert cx1 not in pool .connections [cx1 .addr ]
386
390
assert cx3 in pool .connections [cx1 .addr ]
391
+
392
+
393
+
394
+ @mark_async_test
395
+ async def test_failing_opener_leaves_connections_in_use_alone (opener ):
396
+ pool = AsyncNeo4jPool (
397
+ opener , PoolConfig (), WorkspaceConfig (), ROUTER_ADDRESS
398
+ )
399
+ cx1 = await pool .acquire (READ_ACCESS , 30 , "test_db" , None )
400
+
401
+ opener .side_effect = ServiceUnavailable ("Server overloaded" )
402
+ with pytest .raises ((ServiceUnavailable , SessionExpired )):
403
+ await pool .acquire (READ_ACCESS , 30 , "test_db" , None )
404
+ assert not cx1 .closed ()
Original file line number Diff line number Diff line change 35
35
)
36
36
37
37
from ...._async_compat import mark_sync_test
38
+ from ..._async_compat import (
39
+ mark_sync_test ,
40
+ Mock ,
41
+ )
38
42
from ..work import fake_connection_generator
39
43
40
44
@@ -384,3 +388,17 @@ def liveness_side_effect(*args, **kwargs):
384
388
cx3 .reset .assert_called_once ()
385
389
assert cx1 not in pool .connections [cx1 .addr ]
386
390
assert cx3 in pool .connections [cx1 .addr ]
391
+
392
+
393
+
394
+ @mark_sync_test
395
+ def test_failing_opener_leaves_connections_in_use_alone (opener ):
396
+ pool = Neo4jPool (
397
+ opener , PoolConfig (), WorkspaceConfig (), ROUTER_ADDRESS
398
+ )
399
+ cx1 = pool .acquire (READ_ACCESS , 30 , "test_db" , None )
400
+
401
+ opener .side_effect = ServiceUnavailable ("Server overloaded" )
402
+ with pytest .raises ((ServiceUnavailable , SessionExpired )):
403
+ pool .acquire (READ_ACCESS , 30 , "test_db" , None )
404
+ assert not cx1 .closed ()
You can’t perform that action at this time.
0 commit comments