Skip to content

Commit d95e851

Browse files
add comments to prose tests
1 parent 16990d6 commit d95e851

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

test/integration/server-discovery-and-monitoring/server_discovery_and_monitoring.prose.test.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,21 @@ describe('Server Discovery and Monitoring Prose Tests', function () {
199199
const poolClearedEvents: Array<ConnectionPoolClearedEvent> = [];
200200

201201
beforeEach(async function () {
202+
// 1. Create a test client that listens to CMAP events, with maxConnecting=100.
202203
client = this.configuration.newClient({}, { maxConnecting: 100 });
203204

204205
client.on('connectionCheckOutFailed', e => checkoutFailedEvents.push(e));
205206
client.on('connectionPoolCleared', e => poolClearedEvents.push(e));
206207

207208
await client.connect();
208209

210+
// 2. Run the following commands to set up the rate limiter.
211+
// ```python
212+
// client.admin.command("setParameter", 1, ingressConnectionEstablishmentRateLimiterEnabled=True)
213+
// client.admin.command("setParameter", 1, ingressConnectionEstablishmentRatePerSec=20)
214+
// client.admin.command("setParameter", 1, ingressConnectionEstablishmentBurstCapacitySecs=1)
215+
// client.admin.command("setParameter", 1, ingressConnectionEstablishmentMaxQueueDepth=1)
216+
// ```
209217
const admin = client.db('admin').admin();
210218
await admin.command({
211219
setParameter: 1,
@@ -224,13 +232,17 @@ describe('Server Discovery and Monitoring Prose Tests', function () {
224232
ingressConnectionEstablishmentMaxQueueDepth: 1
225233
});
226234

235+
// 3. Add a document to the test collection so that the sleep operations will actually block:
236+
// `client.test.test.insert_one({})`.
227237
await client.db('test').collection('test').insertOne({});
228238
});
229239

230240
afterEach(async function () {
231-
// give the time to recover from the connection storm before cleaning up.
241+
// 7. Sleep for 1 second to clear the rate limiter.
232242
await sleep(1000);
233243

244+
// 8. Ensure that the following command runs at test teardown even if the test fails.
245+
// `client.admin("setParameter", 1, ingressConnectionEstablishmentRateLimiterEnabled=False)`.
234246
const admin = client.db('admin').admin();
235247
await admin.command({
236248
setParameter: 1,
@@ -244,10 +256,14 @@ describe('Server Discovery and Monitoring Prose Tests', function () {
244256
'does not clear the pool when connections are closed due to connection storms',
245257
{
246258
requires: {
259+
// This test requires MongoDB 7.0+.
247260
mongodb: '>=7.0' // rate limiting added in 7.0
248261
}
249262
},
250263
async function () {
264+
// 4. Run the following find command on the collection in 100 parallel threads/coroutines. Run these commands concurrently
265+
// but block on their completion, and ignore errors raised by the command.
266+
// `client.test.test.find_one({"$where": "function() { sleep(2000); return true; }})`
251267
await Promise.allSettled(
252268
Array.from({ length: 100 }).map(() =>
253269
client
@@ -257,8 +273,11 @@ describe('Server Discovery and Monitoring Prose Tests', function () {
257273
)
258274
);
259275

260-
expect(poolClearedEvents).to.be.empty;
276+
// 5. Assert that at least 10 `ConnectionCheckOutFailedEvent` occurred.
261277
expect(checkoutFailedEvents.length).to.be.at.least(10);
278+
279+
// 6. Assert that 0 `PoolClearedEvent` occurred.
280+
expect(poolClearedEvents).to.be.empty;
262281
}
263282
);
264283
});

0 commit comments

Comments
 (0)