@@ -12,6 +12,7 @@ import {
1212 SERVER_HEARTBEAT_FAILED ,
1313 SERVER_HEARTBEAT_SUCCEEDED
1414} from '../../../src/constants' ;
15+ import { sleep } from '../../tools/utils' ;
1516
1617describe ( 'Server Discovery and Monitoring Prose Tests' , function ( ) {
1718 context ( 'Monitors sleep at least minHeartbeatFrequencyMS between checks' , function ( ) {
@@ -194,28 +195,18 @@ describe('Server Discovery and Monitoring Prose Tests', function () {
194195
195196 context ( 'Connection Pool Backpressure' , function ( ) {
196197 let client : MongoClient ;
197- let utilClient : MongoClient ;
198198 const checkoutFailedEvents : Array < ConnectionCheckOutFailedEvent > = [ ] ;
199199 const poolClearedEvents : Array < ConnectionPoolClearedEvent > = [ ] ;
200200
201- const metadata : MongoDBMetadataUI = {
202- requires : {
203- mongodb : '>=7.0'
204- }
205- } ;
206-
207201 beforeEach ( async function ( ) {
208- client = this . configuration . newClient ( { } , { maxConnecting : 20 } ) ;
202+ client = this . configuration . newClient ( { } , { maxConnecting : 100 } ) ;
209203
210204 client . on ( 'connectionCheckOutFailed' , e => checkoutFailedEvents . push ( e ) ) ;
211205 client . on ( 'connectionPoolCleared' , e => poolClearedEvents . push ( e ) ) ;
212206
213207 await client . connect ( ) ;
214208
215- utilClient = this . configuration . newClient ( ) ;
216- await utilClient . connect ( ) ;
217-
218- const admin = utilClient . db ( 'admin' ) . admin ( ) ;
209+ const admin = client . db ( 'admin' ) . admin ( ) ;
219210 await admin . command ( {
220211 setParameter : 1 ,
221212 ingressConnectionEstablishmentRateLimiterEnabled : true
@@ -233,41 +224,42 @@ describe('Server Discovery and Monitoring Prose Tests', function () {
233224 ingressConnectionEstablishmentMaxQueueDepth : 1
234225 } ) ;
235226
236- await utilClient . db ( 'test' ) . collection ( 'test' ) . insertOne ( { } ) ;
227+ await client . db ( 'test' ) . collection ( 'test' ) . insertOne ( { } ) ;
237228 } ) ;
238229
239230 afterEach ( async function ( ) {
240- const admin = utilClient . db ( 'admin' ) . admin ( ) ;
231+ // give the time to recover from the connection storm before cleaning up.
232+ await sleep ( 1000 ) ;
233+
234+ const admin = client . db ( 'admin' ) . admin ( ) ;
241235 await admin . command ( {
242236 setParameter : 1 ,
243237 ingressConnectionEstablishmentRateLimiterEnabled : false
244238 } ) ;
245239
246- await utilClient . close ( ) ;
247240 await client . close ( ) ;
248241 } ) ;
249242
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- } ) ;
243+ it (
244+ 'does not clear the pool when connections are closed due to connection storms' ,
245+ {
246+ requires : {
247+ mongodb : '>=7.0' // rate limiting added in 7.0
248+ }
249+ } ,
250+ async function ( ) {
251+ await Promise . allSettled (
252+ Array . from ( { length : 100 } ) . map ( ( ) =>
253+ client
254+ . db ( 'test' )
255+ . collection ( 'test' )
256+ . findOne ( { $where : 'function() { sleep(2000); return true; }' } )
257+ )
258+ ) ;
259+
260+ expect ( poolClearedEvents ) . to . be . empty ;
261+ expect ( checkoutFailedEvents . length ) . to . be . greaterThan ( 10 ) ;
262+ }
263+ ) ;
272264 } ) ;
273265} ) ;
0 commit comments