@@ -232,6 +232,36 @@ def test_release_does_not_resets_defunct_connections(opener):
232232 cx1 .reset .asset_not_called ()
233233
234234
235+ def test_multiple_broken_connections_on_close (opener ):
236+ def mock_connection_breaks_on_close (cx ):
237+ def close_side_effect ():
238+ cx .closed .return_value = True
239+ cx .defunct .return_value = True
240+ pool .deactivate (READER_ADDRESS )
241+
242+ cx .attach_mock (Mock (side_effect = close_side_effect ), "close" )
243+
244+ # create pool with 2 idle connections
245+ pool = Neo4jPool (opener , PoolConfig (), WorkspaceConfig (), ROUTER_ADDRESS )
246+ cx1 = pool .acquire (READ_ACCESS , 30 , "test_db" , None )
247+ cx2 = pool .acquire (READ_ACCESS , 30 , "test_db" , None )
248+ pool .release (cx1 )
249+ pool .release (cx2 )
250+
251+ # both will loose connection
252+ mock_connection_breaks_on_close (cx1 )
253+ mock_connection_breaks_on_close (cx2 )
254+
255+ # force pool to close cx1, which will make it realize that the server is
256+ # unreachable
257+ cx1 .stale .return_value = True
258+
259+ cx3 = pool .acquire (READ_ACCESS , 30 , "test_db" , None )
260+
261+ assert cx3 is not cx1
262+ assert cx3 is not cx2
263+
264+
235265def test_failing_opener_leaves_connections_in_use_alone (opener ):
236266 pool = Neo4jPool (opener , PoolConfig (), WorkspaceConfig (), ROUTER_ADDRESS )
237267 cx1 = pool .acquire (READ_ACCESS , 30 , "test_db" , None )
0 commit comments