Skip to content

Commit 4140a99

Browse files
committed
update prose test
1 parent 64c9a11 commit 4140a99

File tree

2 files changed

+16
-38
lines changed

2 files changed

+16
-38
lines changed

test/asynchronous/test_discovery_and_monitoring.py

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -461,24 +461,21 @@ async def test_connection_pool_is_not_cleared(self):
461461
# Create a client that listens to CMAP events, with maxConnecting=100.
462462
client = await self.async_rs_or_single_client(maxConnecting=100, event_listeners=[listener])
463463

464-
# Use an admin client for test setup and teardown to enable and disable the ingress rate limiter.
465-
admin_client = self.client
466-
await admin_client.admin.command(
464+
# Enable the ingress rate limiter.
465+
await client.admin.command(
467466
"setParameter", 1, ingressConnectionEstablishmentRateLimiterEnabled=True
468467
)
469-
await admin_client.admin.command(
470-
"setParameter", 1, ingressConnectionEstablishmentRatePerSec=20
471-
)
472-
await admin_client.admin.command(
468+
await client.admin.command("setParameter", 1, ingressConnectionEstablishmentRatePerSec=20)
469+
await client.admin.command(
473470
"setParameter", 1, ingressConnectionEstablishmentBurstCapacitySecs=1
474471
)
475-
await admin_client.admin.command(
476-
"setParameter", 1, ingressConnectionEstablishmentMaxQueueDepth=1
477-
)
472+
await client.admin.command("setParameter", 1, ingressConnectionEstablishmentMaxQueueDepth=1)
478473

479474
# Disable the ingress rate limiter on teardown.
475+
# Sleep for 1 second before disabling to avoid the rate limiter.
480476
async def teardown():
481-
await admin_client.admin.command(
477+
await asyncio.sleep(1)
478+
await client.admin.command(
482479
"setParameter", 1, ingressConnectionEstablishmentRateLimiterEnabled=False
483480
)
484481

@@ -495,15 +492,6 @@ async def target():
495492
except ConnectionFailure:
496493
pass
497494

498-
# Warm the pool with 10 tasks so there are existing connections.
499-
tasks = []
500-
for _ in range(10):
501-
tasks.append(ConcurrentRunner(target=target))
502-
for t in tasks:
503-
await t.start()
504-
for t in tasks:
505-
await t.join()
506-
507495
# Run 100 parallel operations that contend for connections.
508496
tasks = []
509497
for _ in range(100):

test/test_discovery_and_monitoring.py

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -459,20 +459,19 @@ def test_connection_pool_is_not_cleared(self):
459459
# Create a client that listens to CMAP events, with maxConnecting=100.
460460
client = self.rs_or_single_client(maxConnecting=100, event_listeners=[listener])
461461

462-
# Use an admin client for test setup and teardown to enable and disable the ingress rate limiter.
463-
admin_client = self.client
464-
admin_client.admin.command(
462+
# Enable the ingress rate limiter.
463+
client.admin.command(
465464
"setParameter", 1, ingressConnectionEstablishmentRateLimiterEnabled=True
466465
)
467-
admin_client.admin.command("setParameter", 1, ingressConnectionEstablishmentRatePerSec=20)
468-
admin_client.admin.command(
469-
"setParameter", 1, ingressConnectionEstablishmentBurstCapacitySecs=1
470-
)
471-
admin_client.admin.command("setParameter", 1, ingressConnectionEstablishmentMaxQueueDepth=1)
466+
client.admin.command("setParameter", 1, ingressConnectionEstablishmentRatePerSec=20)
467+
client.admin.command("setParameter", 1, ingressConnectionEstablishmentBurstCapacitySecs=1)
468+
client.admin.command("setParameter", 1, ingressConnectionEstablishmentMaxQueueDepth=1)
472469

473470
# Disable the ingress rate limiter on teardown.
471+
# Sleep for 1 second before disabling to avoid the rate limiter.
474472
def teardown():
475-
admin_client.admin.command(
473+
time.sleep(1)
474+
client.admin.command(
476475
"setParameter", 1, ingressConnectionEstablishmentRateLimiterEnabled=False
477476
)
478477

@@ -489,15 +488,6 @@ def target():
489488
except ConnectionFailure:
490489
pass
491490

492-
# Warm the pool with 10 tasks so there are existing connections.
493-
tasks = []
494-
for _ in range(10):
495-
tasks.append(ConcurrentRunner(target=target))
496-
for t in tasks:
497-
t.start()
498-
for t in tasks:
499-
t.join()
500-
501491
# Run 100 parallel operations that contend for connections.
502492
tasks = []
503493
for _ in range(100):

0 commit comments

Comments
 (0)