@@ -1790,6 +1790,29 @@ async def stall_connect(*args, **kwargs):
1790
1790
# Each ping command should not take more than 2 seconds
1791
1791
self .assertLess (total , 2 )
1792
1792
1793
+ async def test_background_connections_log_on_error (self ):
1794
+ with self .assertLogs ("pymongo.client" , level = "ERROR" ) as cm :
1795
+ client = await self .async_rs_or_single_client (minPoolSize = 1 )
1796
+ # Create a single connection in the pool.
1797
+ await client .admin .command ("ping" )
1798
+
1799
+ # Cause new connections to fail.
1800
+ pool = await async_get_pool (client )
1801
+
1802
+ async def fail_connect (* args , ** kwargs ):
1803
+ raise Exception ("failed to connect" )
1804
+
1805
+ pool .connect = fail_connect
1806
+ # Un-patch Pool.connect to break the cyclic reference.
1807
+ self .addCleanup (delattr , pool , "connect" )
1808
+
1809
+ await pool .reset_without_pause ()
1810
+
1811
+ await async_wait_until (lambda : len (cm .records ) > 0 , "start creating connections" )
1812
+ log_output = "" .join (cm .output )
1813
+ self .assertIn ("failed to connect" , log_output )
1814
+ self .assertIn ("MongoClient background task encountered an error" , log_output )
1815
+
1793
1816
@async_client_context .require_replica_set
1794
1817
async def test_direct_connection (self ):
1795
1818
# direct_connection=True should result in Single topology.
0 commit comments