@@ -467,26 +467,41 @@ async def test_connection_pool_is_not_cleared(self):
467467 # Create a client that listens to CMAP events, with maxConnecting=100.
468468 client = await self .async_rs_or_single_client (maxConnecting = 100 , event_listeners = [listener ])
469469
470- # Enable the ingress rate limiter.
471- await client .admin .command (
472- "setParameter" , 1 , ingressConnectionEstablishmentRateLimiterEnabled = True
473- )
474- await client .admin .command ("setParameter" , 1 , ingressConnectionEstablishmentRatePerSec = 20 )
475- await client .admin .command (
476- "setParameter" , 1 , ingressConnectionEstablishmentBurstCapacitySecs = 1
477- )
478- await client .admin .command ("setParameter" , 1 , ingressConnectionEstablishmentMaxQueueDepth = 1 )
470+ # setParameter needs to be set on each mongos in a sharded cluster
471+ if async_client_context .mongoses :
472+ admin_clients = [
473+ await self .async_single_client ("{}:{}" .format (* address ))
474+ for address in async_client_context .mongoses
475+ ]
476+ else :
477+ admin_clients = [client ]
479478
480479 # Disable the ingress rate limiter on teardown.
481480 # Sleep for 1 second before disabling to avoid the rate limiter.
482481 async def teardown ():
483482 await asyncio .sleep (1 )
484- await client .admin .command (
485- "setParameter" , 1 , ingressConnectionEstablishmentRateLimiterEnabled = False
486- )
483+ for admin_client in admin_clients :
484+ await admin_client .admin .command (
485+ "setParameter" , 1 , ingressConnectionEstablishmentRateLimiterEnabled = False
486+ )
487487
488488 self .addAsyncCleanup (teardown )
489489
490+ # Enable the ingress rate limiter.
491+ for admin_client in admin_clients :
492+ await admin_client .admin .command (
493+ "setParameter" , 1 , ingressConnectionEstablishmentRateLimiterEnabled = True
494+ )
495+ await admin_client .admin .command (
496+ "setParameter" , 1 , ingressConnectionEstablishmentRatePerSec = 20
497+ )
498+ await admin_client .admin .command (
499+ "setParameter" , 1 , ingressConnectionEstablishmentBurstCapacitySecs = 1
500+ )
501+ await admin_client .admin .command (
502+ "setParameter" , 1 , ingressConnectionEstablishmentMaxQueueDepth = 1
503+ )
504+
490505 # Make sure the collection has at least one document.
491506 await client .test .test .delete_many ({})
492507 await client .test .test .insert_one ({})
0 commit comments