2
2
import { type TestConfiguration } from '../../tools/runner/config' ;
3
3
import { runScriptAndGetProcessInfo } from './resource_tracking_script_builder' ;
4
4
5
- describe . only ( 'MongoClient.close() Integration' , ( ) => {
5
+ describe . skip ( 'MongoClient.close() Integration' , ( ) => {
6
6
// note: these tests are set-up in accordance of the resource ownership tree
7
7
8
8
let config : TestConfiguration ;
@@ -76,33 +76,45 @@ describe.only('MongoClient.close() Integration', () => {
76
76
describe ( 'Node.js resource: Server Selection Timer' , ( ) => {
77
77
describe ( 'after a Topology is created through client.connect()' , ( ) => {
78
78
it ( 'server selection timers are cleaned up by client.close()' , async ( ) => {
79
- const run = async function ( { MongoClient, uri, expect, sinon, sleep, mongodb, getTimerCount } ) {
80
- const serverSelectionTimeoutMS = 2222 ;
81
- const client = new MongoClient ( uri , { minPoolSize : 1 , serverSelectionTimeoutMS } ) ;
82
- const timers = require ( 'timers' ) ;
83
- const timeoutStartedSpy = sinon . spy ( timers , 'setTimeout' ) ;
84
- let serverSelectionTimeoutStarted = false ;
85
-
86
- // make server selection hang so check out timer isn't cleared and check that the timeout has started
87
- sinon . stub ( Promise , 'race' ) . callsFake ( async ( [ serverPromise , timeout ] ) => {
88
- serverSelectionTimeoutStarted = timeoutStartedSpy . getCalls ( ) . filter ( r => r . args . includes ( serverSelectionTimeoutMS ) ) . flat ( ) . length > 0 ;
89
- await timeout ;
90
- } ) ;
79
+ const run = async function ( {
80
+ MongoClient,
81
+ uri,
82
+ expect,
83
+ sinon,
84
+ sleep,
85
+ mongodb,
86
+ getTimerCount,
87
+ timers
88
+ } ) {
89
+ const serverSelectionTimeoutMS = 2222 ;
90
+ const client = new MongoClient ( uri , { minPoolSize : 1 , serverSelectionTimeoutMS } ) ;
91
+ const timeoutStartedSpy = sinon . spy ( timers , 'setTimeout' ) ;
92
+ let serverSelectionTimeoutStarted = false ;
93
+
94
+ // make server selection hang so check out timer isn't cleared and check that the timeout has started
95
+ sinon . stub ( Promise , 'race' ) . callsFake ( async ( [ _serverPromise , timeout ] ) => {
96
+ serverSelectionTimeoutStarted =
97
+ timeoutStartedSpy
98
+ . getCalls ( )
99
+ . filter ( r => r . args . includes ( serverSelectionTimeoutMS ) )
100
+ . flat ( ) . length > 0 ;
101
+ await timeout ;
102
+ } ) ;
91
103
92
- const insertPromise = client . db ( 'db' ) . collection ( 'collection' ) . insertOne ( { x : 1 } ) ;
104
+ const insertPromise = client . db ( 'db' ) . collection ( 'collection' ) . insertOne ( { x : 1 } ) ;
93
105
94
- // don't allow entire server selection timer to elapse to ensure close is called mid-timeout
95
- await sleep ( serverSelectionTimeoutMS / 2 ) ;
96
- expect ( serverSelectionTimeoutStarted ) . to . be . true ;
106
+ // don't allow entire server selection timer to elapse to ensure close is called mid-timeout
107
+ await sleep ( serverSelectionTimeoutMS / 2 ) ;
108
+ expect ( serverSelectionTimeoutStarted ) . to . be . true ;
97
109
98
- expect ( getTimerCount ( ) ) . to . not . equal ( 0 ) ;
99
- await client . close ( ) ;
100
- expect ( getTimerCount ( ) ) . to . equal ( 0 ) ;
110
+ expect ( getTimerCount ( ) ) . to . not . equal ( 0 ) ;
111
+ await client . close ( ) ;
112
+ expect ( getTimerCount ( ) ) . to . equal ( 0 ) ;
101
113
102
- const err = await insertPromise . catch ( e => e ) ;
103
- expect ( err ) . to . be . instanceOf ( mongodb . MongoServerSelectionError ) ;
104
- } ;
105
- await runScriptAndGetProcessInfo ( 'timer-server-selection' , config , run ) ;
114
+ const err = await insertPromise . catch ( e => e ) ;
115
+ expect ( err ) . to . be . instanceOf ( mongodb . MongoServerSelectionError ) ;
116
+ } ;
117
+ await runScriptAndGetProcessInfo ( 'timer-server-selection' , config , run ) ;
106
118
} ) ;
107
119
} ) ;
108
120
} ) ;
@@ -119,57 +131,66 @@ describe.only('MongoClient.close() Integration', () => {
119
131
describe ( 'MonitorInterval' , ( ) => {
120
132
describe ( 'Node.js resource: Timer' , ( ) => {
121
133
describe ( 'after a new monitor is made' , ( ) => {
122
- it ( 'monitor interval timer is cleaned up by client.close()' , metadata , async function ( ) {
123
- const run = async function ( { MongoClient, uri, expect, sleep, getTimerCount } ) {
124
- const heartbeatFrequencyMS = 2000 ;
125
- const client = new MongoClient ( uri , { heartbeatFrequencyMS } ) ;
126
- let heartbeatHappened = false ;
127
- client . on ( 'serverHeartbeatSucceeded' , ( ) => heartbeatHappened = true ) ;
128
- await client . connect ( ) ;
129
- await sleep ( heartbeatFrequencyMS * 2.5 ) ;
130
- expect ( heartbeatHappened ) . to . be . true ;
134
+ it (
135
+ 'monitor interval timer is cleaned up by client.close()' ,
136
+ metadata ,
137
+ async function ( ) {
138
+ const run = async function ( { MongoClient, uri, expect, sleep, getTimerCount } ) {
139
+ const heartbeatFrequencyMS = 2000 ;
140
+ const client = new MongoClient ( uri , { heartbeatFrequencyMS } ) ;
141
+ let heartbeatHappened = false ;
142
+ client . on ( 'serverHeartbeatSucceeded' , ( ) => ( heartbeatHappened = true ) ) ;
143
+ await client . connect ( ) ;
144
+ await sleep ( heartbeatFrequencyMS * 2.5 ) ;
145
+ expect ( heartbeatHappened ) . to . be . true ;
131
146
132
- function getMonitorTimer ( servers ) {
133
- for ( const server of servers ) {
134
- return server [ 1 ] ?. monitor . monitorId . timerId ;
147
+ function getMonitorTimer ( servers ) {
148
+ for ( const server of servers ) {
149
+ return server [ 1 ] ?. monitor . monitorId . timerId ;
150
+ }
135
151
}
136
- } ;
137
- const servers = client . topology . s . servers ;
138
- expect ( getMonitorTimer ( servers ) ) . to . exist ;
139
- await client . close ( ) ;
140
- expect ( getMonitorTimer ( servers ) ) . to . not . exist ;
152
+ const servers = client . topology . s . servers ;
153
+ expect ( getMonitorTimer ( servers ) ) . to . exist ;
154
+ await client . close ( ) ;
155
+ expect ( getMonitorTimer ( servers ) ) . to . not . exist ;
141
156
142
- expect ( getTimerCount ( ) ) . to . equal ( 0 ) ;
143
- } ;
144
- await runScriptAndGetProcessInfo ( 'timer-monitor-interval' , config , run ) ;
145
- } ) ;
157
+ expect ( getTimerCount ( ) ) . to . equal ( 0 ) ;
158
+ } ;
159
+ await runScriptAndGetProcessInfo ( 'timer-monitor-interval' , config , run ) ;
160
+ }
161
+ ) ;
146
162
} ) ;
147
163
148
164
describe ( 'after a heartbeat fails' , ( ) => {
149
- it ( 'the new monitor interval timer is cleaned up by client.close()' , metadata , async ( ) => {
150
- const run = async function ( { MongoClient, uri, expect, sleep, getTimerCount } ) {
151
- const heartbeatFrequencyMS = 2000 ;
152
- const client = new MongoClient ( 'mongodb://fakeUri' , { heartbeatFrequencyMS } ) ;
153
- let heartbeatHappened = false ;
154
- client . on ( 'serverHeartbeatFailed' , ( ) => heartbeatHappened = true ) ;
155
- client . connect ( ) ;
156
- await sleep ( heartbeatFrequencyMS * 2.5 ) ;
157
- expect ( heartbeatHappened ) . to . be . true ;
158
-
159
- function getMonitorTimer ( servers ) {
160
- for ( const server of servers ) {
161
- return server [ 1 ] ?. monitor . monitorId . timerId ;
165
+ it (
166
+ 'the new monitor interval timer is cleaned up by client.close()' ,
167
+ metadata ,
168
+ async ( ) => {
169
+ /* eslint-disable-next-line @typescript-eslint/no-unused-vars */
170
+ const run = async function ( { MongoClient, uri, expect, sleep, getTimerCount } ) {
171
+ const heartbeatFrequencyMS = 2000 ;
172
+ const client = new MongoClient ( 'mongodb://fakeUri' , { heartbeatFrequencyMS } ) ;
173
+ let heartbeatHappened = false ;
174
+ client . on ( 'serverHeartbeatFailed' , ( ) => ( heartbeatHappened = true ) ) ;
175
+ client . connect ( ) ;
176
+ await sleep ( heartbeatFrequencyMS * 2.5 ) ;
177
+ expect ( heartbeatHappened ) . to . be . true ;
178
+
179
+ function getMonitorTimer ( servers ) {
180
+ for ( const server of servers ) {
181
+ return server [ 1 ] ?. monitor . monitorId . timerId ;
182
+ }
162
183
}
163
- } ;
164
- const servers = client . topology . s . servers ;
165
- expect ( getMonitorTimer ( servers ) ) . to . exist ;
166
- await client . close ( ) ;
167
- expect ( getMonitorTimer ( servers ) ) . to . not . exist ;
184
+ const servers = client . topology . s . servers ;
185
+ expect ( getMonitorTimer ( servers ) ) . to . exist ;
186
+ await client . close ( ) ;
187
+ expect ( getMonitorTimer ( servers ) ) . to . not . exist ;
168
188
169
- expect ( getTimerCount ( ) ) . to . equal ( 0 ) ;
170
- } ;
171
- await runScriptAndGetProcessInfo ( 'timer-heartbeat-failed-monitor' , config , run ) ;
172
- } ) ;
189
+ expect ( getTimerCount ( ) ) . to . equal ( 0 ) ;
190
+ } ;
191
+ await runScriptAndGetProcessInfo ( 'timer-heartbeat-failed-monitor' , config , run ) ;
192
+ }
193
+ ) ;
173
194
} ) ;
174
195
} ) ;
175
196
} ) ;
@@ -211,36 +232,40 @@ describe.only('MongoClient.close() Integration', () => {
211
232
describe ( 'RTT Pinger' , ( ) => {
212
233
describe ( 'Node.js resource: Timer' , ( ) => {
213
234
describe ( 'after entering monitor streaming mode ' , ( ) => {
214
- it ( 'the rtt pinger timer is cleaned up by client.close()' , metadata , async function ( ) {
215
- const run = async function ( { MongoClient, uri, expect, sleep, getTimerCount } ) {
216
- const heartbeatFrequencyMS = 2000 ;
217
- const client = new MongoClient ( uri , {
218
- serverMonitoringMode : 'stream' ,
219
- heartbeatFrequencyMS
220
- } ) ;
221
- await client . connect ( ) ;
235
+ it (
236
+ 'the rtt pinger timer is cleaned up by client.close()' ,
237
+ metadata ,
238
+ async function ( ) {
239
+ const run = async function ( { MongoClient, uri, expect, sleep, getTimerCount } ) {
240
+ const heartbeatFrequencyMS = 2000 ;
241
+ const client = new MongoClient ( uri , {
242
+ serverMonitoringMode : 'stream' ,
243
+ heartbeatFrequencyMS
244
+ } ) ;
245
+ await client . connect ( ) ;
222
246
223
- let heartbeatHappened = false ;
224
- client . on ( 'serverHeartbeatSucceeded' , ( ) => heartbeatHappened = true ) ;
225
- await sleep ( heartbeatFrequencyMS * 2.5 ) ;
226
- expect ( heartbeatHappened ) . to . be . true ;
247
+ let heartbeatHappened = false ;
248
+ client . on ( 'serverHeartbeatSucceeded' , ( ) => ( heartbeatHappened = true ) ) ;
249
+ await sleep ( heartbeatFrequencyMS * 2.5 ) ;
250
+ expect ( heartbeatHappened ) . to . be . true ;
227
251
228
- function getRttTimer ( servers ) {
229
- for ( const server of servers ) {
230
- return server [ 1 ] ?. monitor . rttPinger . monitorId ;
252
+ function getRttTimer ( servers ) {
253
+ for ( const server of servers ) {
254
+ return server [ 1 ] ?. monitor . rttPinger . monitorId ;
255
+ }
231
256
}
232
- } ;
233
257
234
- const servers = client . topology . s . servers ;
235
- expect ( getRttTimer ( servers ) ) . to . exist ;
258
+ const servers = client . topology . s . servers ;
259
+ expect ( getRttTimer ( servers ) ) . to . exist ;
236
260
237
- await client . close ( ) ;
238
- expect ( getRttTimer ( servers ) ) . to . not . exist ;
261
+ await client . close ( ) ;
262
+ expect ( getRttTimer ( servers ) ) . to . not . exist ;
239
263
240
- expect ( getTimerCount ( ) ) . to . equal ( 0 ) ;
241
- } ;
242
- await runScriptAndGetProcessInfo ( 'timer-rtt-monitor' , config , run ) ;
243
- } ) ;
264
+ expect ( getTimerCount ( ) ) . to . equal ( 0 ) ;
265
+ } ;
266
+ await runScriptAndGetProcessInfo ( 'timer-rtt-monitor' , config , run ) ;
267
+ }
268
+ ) ;
244
269
} ) ;
245
270
} ) ;
246
271
@@ -315,7 +340,6 @@ describe.only('MongoClient.close() Integration', () => {
315
340
316
341
const servers = client . topology ?. s . servers ;
317
342
318
-
319
343
function getMinPoolSizeTimer ( servers ) {
320
344
for ( const server of servers ) {
321
345
return server [ 1 ] . pool . minPoolSizeTimer ;
@@ -336,7 +360,15 @@ describe.only('MongoClient.close() Integration', () => {
336
360
describe ( 'Node.js resource: checkOut Timer' , ( ) => {
337
361
describe ( 'after new connection pool is created' , ( ) => {
338
362
it ( 'the wait queue timer is cleaned up by client.close()' , async function ( ) {
339
- const run = async function ( { MongoClient, uri, expect, sinon, sleep, getTimerCount } ) {
363
+ const run = async function ( {
364
+ MongoClient,
365
+ uri,
366
+ expect,
367
+ sinon,
368
+ sleep,
369
+ getTimerCount,
370
+ timers
371
+ } ) {
340
372
const waitQueueTimeoutMS = 1515 ;
341
373
342
374
// configure failPoint
@@ -345,38 +377,56 @@ describe.only('MongoClient.close() Integration', () => {
345
377
const failPoint = {
346
378
configureFailPoint : 'failCommand' ,
347
379
mode : { times : 1 } ,
348
- data : { blockConnection : true , blockTimeMS : waitQueueTimeoutMS * 3 , failCommands : [ 'insert' ] }
349
- }
380
+ data : {
381
+ blockConnection : true ,
382
+ blockTimeMS : waitQueueTimeoutMS * 3 ,
383
+ failCommands : [ 'insert' ]
384
+ }
385
+ } ;
350
386
await utilClient . db ( 'admin' ) . command ( failPoint ) ;
351
387
352
- const timers = require ( 'timers' ) ;
353
388
const timeoutStartedSpy = sinon . spy ( timers , 'setTimeout' ) ;
354
389
355
- const client = new MongoClient ( uri , { minPoolSize : 1 , maxPoolSize : 1 , waitQueueTimeoutMS } ) ;
356
- const insertPromise = client . db ( 'db' ) . collection ( 'collection' ) . insertOne ( { x : 1 } ) . catch ( e => e ) ;
357
- client . db ( 'db' ) . collection ( 'collection' ) . insertOne ( { x : 1 } ) . catch ( e => e ) ;
390
+ const client = new MongoClient ( uri , {
391
+ minPoolSize : 1 ,
392
+ maxPoolSize : 1 ,
393
+ waitQueueTimeoutMS
394
+ } ) ;
395
+ const insertPromise = client
396
+ . db ( 'db' )
397
+ . collection ( 'collection' )
398
+ . insertOne ( { x : 1 } )
399
+ . catch ( e => e ) ;
400
+ client
401
+ . db ( 'db' )
402
+ . collection ( 'collection' )
403
+ . insertOne ( { x : 1 } )
404
+ . catch ( e => e ) ;
358
405
359
406
// don't allow entire checkout timer to elapse to ensure close is called mid-timeout
360
407
await sleep ( waitQueueTimeoutMS / 2 ) ;
361
- const checkoutTimeoutStarted = timeoutStartedSpy . getCalls ( ) . filter ( r => r . args . includes ( waitQueueTimeoutMS ) ) . flat ( ) . length > 0 ;
408
+ const checkoutTimeoutStarted =
409
+ timeoutStartedSpy
410
+ . getCalls ( )
411
+ . filter ( r => r . args . includes ( waitQueueTimeoutMS ) )
412
+ . flat ( ) . length > 0 ;
362
413
expect ( checkoutTimeoutStarted ) . to . be . true ;
363
414
364
415
await client . close ( ) ;
365
416
expect ( getTimerCount ( ) ) . to . equal ( 0 ) ;
366
417
// un-configure fail{oint
367
- await utilClient
368
- . db ( )
369
- . admin ( )
370
- . command ( {
371
- configureFailPoint : 'failCommand' ,
372
- mode : 'off'
373
- } ) ;
418
+ await utilClient . db ( ) . admin ( ) . command ( {
419
+ configureFailPoint : 'failCommand' ,
420
+ mode : 'off'
421
+ } ) ;
374
422
375
423
await utilClient . close ( ) ;
376
424
377
425
const err = await insertPromise ;
378
426
expect ( err ) . to . be . instanceOf ( Error ) ;
379
- expect ( err . message ) . to . contain ( 'Timed out while checking out a connection from connection pool' ) ;
427
+ expect ( err . message ) . to . contain (
428
+ 'Timed out while checking out a connection from connection pool'
429
+ ) ;
380
430
} ;
381
431
await runScriptAndGetProcessInfo ( 'timer-check-out' , config , run ) ;
382
432
} ) ;
@@ -422,19 +472,23 @@ describe.only('MongoClient.close() Integration', () => {
422
472
// requires an srv environment that can transition to sharded
423
473
const metadata : MongoDBMetadataUI = {
424
474
requires : {
425
- predicate : ( ) => process . env . ATLAS_SRV_REPL ? 'Skipped: this test requires an SRV environment' : true
475
+ predicate : ( ) =>
476
+ process . env . ATLAS_SRV_REPL ? 'Skipped: this test requires an SRV environment' : true
426
477
}
427
478
} ;
428
479
429
480
describe ( 'after SRVPoller is created' , ( ) => {
430
- it . only ( 'timers are cleaned up by client.close()' , metadata , async ( ) => {
431
- const run = async function ( { MongoClient, uri, expect, sinon , getTimerCount } ) {
481
+ it ( 'timers are cleaned up by client.close()' , metadata , async ( ) => {
482
+ const run = async function ( { MongoClient, uri, expect, getTimerCount } ) {
432
483
const client = new MongoClient ( uri ) ;
433
484
await client . connect ( ) ;
434
485
const description = client . topology . s . description ;
435
486
// simulate transition to sharded
436
- client . topology . emit ( 'topologyDescriptionChanged' , description , { ... description , type : 'Sharded' } ) ;
437
- expect ( client . topology . s . srvPoller ?. _timeout ) . to . exist ;
487
+ client . topology . emit ( 'topologyDescriptionChanged' , description , {
488
+ ...description ,
489
+ type : 'Sharded'
490
+ } ) ;
491
+ expect ( client . topology . s . srvPoller . _timeout ) . to . exist ;
438
492
await client . close ( ) ;
439
493
expect ( getTimerCount ( ) ) . to . equal ( 0 ) ;
440
494
} ;
@@ -581,4 +635,4 @@ describe.only('MongoClient.close() Integration', () => {
581
635
it . skip ( 'all active server-side cursors are closed by client.close()' , async function ( ) { } ) ;
582
636
} ) ;
583
637
} ) ;
584
- } ) ;
638
+ } ) ;
0 commit comments