@@ -7,6 +7,7 @@ import { inspect } from 'util';
77import {
88 AbstractCursor ,
99 type Collection ,
10+ type CommandStartedEvent ,
1011 CursorTimeoutContext ,
1112 CursorTimeoutMode ,
1213 type FindCursor ,
@@ -17,7 +18,8 @@ import {
1718 MongoServerError ,
1819 TimeoutContext
1920} from '../../mongodb' ;
20- import { type FailPoint } from '../../tools/utils' ;
21+ import { clearFailPoint , configureFailPoint } from '../../tools/utils' ;
22+ import { filterForCommands } from '../shared' ;
2123
2224describe ( 'class AbstractCursor' , function ( ) {
2325 describe ( 'regression tests NODE-5372' , function ( ) {
@@ -405,9 +407,11 @@ describe('class AbstractCursor', function () {
405407 let client : MongoClient ;
406408 let collection : Collection ;
407409 let context : CursorTimeoutContext ;
410+ const commands : CommandStartedEvent [ ] = [ ] ;
408411
409412 beforeEach ( async function ( ) {
410- client = this . configuration . newClient ( ) ;
413+ client = this . configuration . newClient ( { } , { monitorCommands : true } ) ;
414+ client . on ( 'commandStarted' , filterForCommands ( 'killCursors' , commands ) ) ;
411415
412416 collection = client . db ( 'abstract_cursor_integration' ) . collection ( 'test' ) ;
413417
@@ -472,30 +476,48 @@ describe('class AbstractCursor', function () {
472476 } ) ;
473477 } ) ;
474478
475- describe ( 'when the cursor refreshes the timeout for killCursors' , function ( ) {
476- it (
477- 'the provided timeoutContext is not modified' ,
478- {
479- requires : {
480- mongodb : '>=4.4'
481- }
482- } ,
483- async function ( ) {
484- await client . db ( 'admin' ) . command ( {
479+ describe ( 'when the cursor refreshes the timeout for killCursors' + i , function ( ) {
480+ let uri : string ;
481+
482+ before ( function ( ) {
483+ uri = this . configuration . url ( { useMultipleMongoses : false } ) ;
484+ } ) ;
485+
486+ beforeEach ( async function ( ) {
487+ commands . length = 0 ;
488+ await configureFailPoint (
489+ this . configuration ,
490+ {
485491 configureFailPoint : 'failCommand' ,
486492 mode : { times : 1 } ,
487493 data : {
488494 failCommands : [ 'getMore' ] ,
489495 blockConnection : true ,
490496 blockTimeMS : 5000
491497 }
492- } as FailPoint ) ;
498+ } ,
499+ uri
500+ ) ;
501+ } ) ;
493502
503+ afterEach ( async function ( ) {
504+ await clearFailPoint ( this . configuration , uri ) ;
505+ } ) ;
506+
507+ it (
508+ 'the provided timeoutContext is not modified' + i ,
509+ {
510+ requires : {
511+ mongodb : '>=4.4' ,
512+ topology : '!load-balanced'
513+ }
514+ } ,
515+ async function ( ) {
494516 const cursor = collection . find (
495517 { } ,
496518 {
497519 timeoutContext : context ,
498- timeoutMS : 1000 ,
520+ timeoutMS : 150 ,
499521 timeoutMode : CursorTimeoutMode . LIFETIME ,
500522 batchSize : 1
501523 }
@@ -504,7 +526,6 @@ describe('class AbstractCursor', function () {
504526 const error = await cursor . toArray ( ) . catch ( e => e ) ;
505527
506528 expect ( error ) . to . be . instanceof ( MongoOperationTimeoutError ) ;
507- // @ts -expect-error We know we have a CSOT timeout context but TS does not.
508529 expect ( context . timeoutContext . remainingTimeMS ) . to . be . lessThan ( 0 ) ;
509530 }
510531 ) ;
0 commit comments