Skip to content

Commit 2aa99d2

Browse files
add prose test
1 parent c363bea commit 2aa99d2

File tree

1 file changed

+84
-1
lines changed

1 file changed

+84
-1
lines changed

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

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { expect } from 'chai';
22
import { once } from 'events';
33

4-
import { type MongoClient } from '../../../src';
4+
import {
5+
type ConnectionCheckOutFailedEvent,
6+
type ConnectionPoolClearedEvent,
7+
type MongoClient
8+
} from '../../../src';
59
import {
610
CONNECTION_POOL_CLEARED,
711
CONNECTION_POOL_READY,
@@ -187,4 +191,83 @@ describe('Server Discovery and Monitoring Prose Tests', function () {
187191
}
188192
});
189193
});
194+
195+
context('Connection Pool Backpressure', function () {
196+
let client: MongoClient;
197+
let utilClient: MongoClient;
198+
const checkoutFailedEvents: Array<ConnectionCheckOutFailedEvent> = [];
199+
const poolClearedEvents: Array<ConnectionPoolClearedEvent> = [];
200+
201+
const metadata: MongoDBMetadataUI = {
202+
requires: {
203+
mongodb: '>=7.0'
204+
}
205+
};
206+
207+
beforeEach(async function () {
208+
client = this.configuration.newClient({}, { maxConnecting: 20 });
209+
210+
client.on('connectionCheckOutFailed', e => checkoutFailedEvents.push(e));
211+
client.on('connectionPoolCleared', e => poolClearedEvents.push(e));
212+
213+
await client.connect();
214+
215+
utilClient = this.configuration.newClient();
216+
await utilClient.connect();
217+
218+
const admin = utilClient.db('admin').admin();
219+
await admin.command({
220+
setParameter: 1,
221+
ingressConnectionEstablishmentRateLimiterEnabled: true
222+
});
223+
await admin.command({
224+
setParameter: 1,
225+
ingressConnectionEstablishmentRatePerSec: 20
226+
});
227+
await admin.command({
228+
setParameter: 1,
229+
ingressConnectionEstablishmentBurstCapacitySecs: 1
230+
});
231+
await admin.command({
232+
setParameter: 1,
233+
ingressConnectionEstablishmentMaxQueueDepth: 1
234+
});
235+
236+
await utilClient.db('test').collection('test').insertOne({});
237+
});
238+
239+
afterEach(async function () {
240+
const admin = utilClient.db('admin').admin();
241+
await admin.command({
242+
setParameter: 1,
243+
ingressConnectionEstablishmentRateLimiterEnabled: false
244+
});
245+
246+
await utilClient.close();
247+
await client.close();
248+
});
249+
250+
it('runs', metadata, async function () {
251+
await Promise.allSettled(
252+
Array.from({ length: 10 }).map(() =>
253+
client
254+
.db('test')
255+
.collection('test')
256+
.findOne({ $where: 'function() { sleep(2000); return true; }' })
257+
)
258+
);
259+
260+
await Promise.allSettled(
261+
Array.from({ length: 100 }).map(() =>
262+
client
263+
.db('test')
264+
.collection('test')
265+
.findOne({ $where: 'function() { sleep(2000); return true; }' })
266+
)
267+
);
268+
269+
expect(poolClearedEvents).to.be.empty;
270+
expect(checkoutFailedEvents.length).to.be.greaterThan(10);
271+
});
272+
});
190273
});

0 commit comments

Comments
 (0)