From c477dd6ef300a171692048a7fd6658ee86633f00 Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Tue, 30 Jun 2026 16:50:06 -0400 Subject: [PATCH 1/2] PYTHON-5875 - Call setParameter on each mongos for test_connection_pool_is_not_cleared --- .../test_discovery_and_monitoring.py | 37 +++++++++++++------ test/test_discovery_and_monitoring.py | 34 ++++++++++++----- 2 files changed, 51 insertions(+), 20 deletions(-) diff --git a/test/asynchronous/test_discovery_and_monitoring.py b/test/asynchronous/test_discovery_and_monitoring.py index 6867a12060..49ca0e286e 100644 --- a/test/asynchronous/test_discovery_and_monitoring.py +++ b/test/asynchronous/test_discovery_and_monitoring.py @@ -467,23 +467,38 @@ async def test_connection_pool_is_not_cleared(self): # Create a client that listens to CMAP events, with maxConnecting=100. client = await self.async_rs_or_single_client(maxConnecting=100, event_listeners=[listener]) + # setParameter needs to be set on each mongos in a sharded cluster + if async_client_context.mongoses: + admin_clients = [ + await self.async_single_client("{}:{}".format(*address)) + for address in async_client_context.mongoses + ] + else: + admin_clients = [client] + # Enable the ingress rate limiter. - await client.admin.command( - "setParameter", 1, ingressConnectionEstablishmentRateLimiterEnabled=True - ) - await client.admin.command("setParameter", 1, ingressConnectionEstablishmentRatePerSec=20) - await client.admin.command( - "setParameter", 1, ingressConnectionEstablishmentBurstCapacitySecs=1 - ) - await client.admin.command("setParameter", 1, ingressConnectionEstablishmentMaxQueueDepth=1) + for admin_client in admin_clients: + await admin_client.admin.command( + "setParameter", 1, ingressConnectionEstablishmentRateLimiterEnabled=True + ) + await admin_client.admin.command( + "setParameter", 1, ingressConnectionEstablishmentRatePerSec=20 + ) + await admin_client.admin.command( + "setParameter", 1, ingressConnectionEstablishmentBurstCapacitySecs=1 + ) + await admin_client.admin.command( + "setParameter", 1, ingressConnectionEstablishmentMaxQueueDepth=1 + ) # Disable the ingress rate limiter on teardown. # Sleep for 1 second before disabling to avoid the rate limiter. async def teardown(): await asyncio.sleep(1) - await client.admin.command( - "setParameter", 1, ingressConnectionEstablishmentRateLimiterEnabled=False - ) + for admin_client in admin_clients: + await admin_client.admin.command( + "setParameter", 1, ingressConnectionEstablishmentRateLimiterEnabled=False + ) self.addAsyncCleanup(teardown) diff --git a/test/test_discovery_and_monitoring.py b/test/test_discovery_and_monitoring.py index 1f2c21f9c1..96b0d06cc1 100644 --- a/test/test_discovery_and_monitoring.py +++ b/test/test_discovery_and_monitoring.py @@ -465,21 +465,37 @@ def test_connection_pool_is_not_cleared(self): # Create a client that listens to CMAP events, with maxConnecting=100. client = self.rs_or_single_client(maxConnecting=100, event_listeners=[listener]) + # setParameter needs to be set on each mongos in a sharded cluster + if client_context.mongoses: + admin_clients = [ + self.single_client("{}:{}".format(*address)) for address in client_context.mongoses + ] + else: + admin_clients = [client] + # Enable the ingress rate limiter. - client.admin.command( - "setParameter", 1, ingressConnectionEstablishmentRateLimiterEnabled=True - ) - client.admin.command("setParameter", 1, ingressConnectionEstablishmentRatePerSec=20) - client.admin.command("setParameter", 1, ingressConnectionEstablishmentBurstCapacitySecs=1) - client.admin.command("setParameter", 1, ingressConnectionEstablishmentMaxQueueDepth=1) + for admin_client in admin_clients: + admin_client.admin.command( + "setParameter", 1, ingressConnectionEstablishmentRateLimiterEnabled=True + ) + admin_client.admin.command( + "setParameter", 1, ingressConnectionEstablishmentRatePerSec=20 + ) + admin_client.admin.command( + "setParameter", 1, ingressConnectionEstablishmentBurstCapacitySecs=1 + ) + admin_client.admin.command( + "setParameter", 1, ingressConnectionEstablishmentMaxQueueDepth=1 + ) # Disable the ingress rate limiter on teardown. # Sleep for 1 second before disabling to avoid the rate limiter. def teardown(): time.sleep(1) - client.admin.command( - "setParameter", 1, ingressConnectionEstablishmentRateLimiterEnabled=False - ) + for admin_client in admin_clients: + admin_client.admin.command( + "setParameter", 1, ingressConnectionEstablishmentRateLimiterEnabled=False + ) self.addCleanup(teardown) From de3c0ac24811c372f4b942370045f8a60a54fe7b Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Wed, 1 Jul 2026 09:31:08 -0400 Subject: [PATCH 2/2] CP review --- .../test_discovery_and_monitoring.py | 22 +++++++++---------- test/test_discovery_and_monitoring.py | 22 +++++++++---------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/test/asynchronous/test_discovery_and_monitoring.py b/test/asynchronous/test_discovery_and_monitoring.py index 49ca0e286e..6fc0e09a19 100644 --- a/test/asynchronous/test_discovery_and_monitoring.py +++ b/test/asynchronous/test_discovery_and_monitoring.py @@ -476,6 +476,17 @@ async def test_connection_pool_is_not_cleared(self): else: admin_clients = [client] + # Disable the ingress rate limiter on teardown. + # Sleep for 1 second before disabling to avoid the rate limiter. + async def teardown(): + await asyncio.sleep(1) + for admin_client in admin_clients: + await admin_client.admin.command( + "setParameter", 1, ingressConnectionEstablishmentRateLimiterEnabled=False + ) + + self.addAsyncCleanup(teardown) + # Enable the ingress rate limiter. for admin_client in admin_clients: await admin_client.admin.command( @@ -491,17 +502,6 @@ async def test_connection_pool_is_not_cleared(self): "setParameter", 1, ingressConnectionEstablishmentMaxQueueDepth=1 ) - # Disable the ingress rate limiter on teardown. - # Sleep for 1 second before disabling to avoid the rate limiter. - async def teardown(): - await asyncio.sleep(1) - for admin_client in admin_clients: - await admin_client.admin.command( - "setParameter", 1, ingressConnectionEstablishmentRateLimiterEnabled=False - ) - - self.addAsyncCleanup(teardown) - # Make sure the collection has at least one document. await client.test.test.delete_many({}) await client.test.test.insert_one({}) diff --git a/test/test_discovery_and_monitoring.py b/test/test_discovery_and_monitoring.py index 96b0d06cc1..612d52afbf 100644 --- a/test/test_discovery_and_monitoring.py +++ b/test/test_discovery_and_monitoring.py @@ -473,6 +473,17 @@ def test_connection_pool_is_not_cleared(self): else: admin_clients = [client] + # Disable the ingress rate limiter on teardown. + # Sleep for 1 second before disabling to avoid the rate limiter. + def teardown(): + time.sleep(1) + for admin_client in admin_clients: + admin_client.admin.command( + "setParameter", 1, ingressConnectionEstablishmentRateLimiterEnabled=False + ) + + self.addCleanup(teardown) + # Enable the ingress rate limiter. for admin_client in admin_clients: admin_client.admin.command( @@ -488,17 +499,6 @@ def test_connection_pool_is_not_cleared(self): "setParameter", 1, ingressConnectionEstablishmentMaxQueueDepth=1 ) - # Disable the ingress rate limiter on teardown. - # Sleep for 1 second before disabling to avoid the rate limiter. - def teardown(): - time.sleep(1) - for admin_client in admin_clients: - admin_client.admin.command( - "setParameter", 1, ingressConnectionEstablishmentRateLimiterEnabled=False - ) - - self.addCleanup(teardown) - # Make sure the collection has at least one document. client.test.test.delete_many({}) client.test.test.insert_one({})