@@ -7,6 +7,7 @@ import { inspect } from 'util';
7
7
import {
8
8
AbstractCursor ,
9
9
type Collection ,
10
+ type CommandStartedEvent ,
10
11
CursorTimeoutContext ,
11
12
CursorTimeoutMode ,
12
13
type FindCursor ,
@@ -17,7 +18,8 @@ import {
17
18
MongoServerError ,
18
19
TimeoutContext
19
20
} from '../../mongodb' ;
20
- import { type FailPoint } from '../../tools/utils' ;
21
+ import { clearFailPoint , configureFailPoint } from '../../tools/utils' ;
22
+ import { filterForCommands } from '../shared' ;
21
23
22
24
describe ( 'class AbstractCursor' , function ( ) {
23
25
describe ( 'regression tests NODE-5372' , function ( ) {
@@ -405,9 +407,11 @@ describe('class AbstractCursor', function () {
405
407
let client : MongoClient ;
406
408
let collection : Collection ;
407
409
let context : CursorTimeoutContext ;
410
+ const commands : CommandStartedEvent [ ] = [ ] ;
408
411
409
412
beforeEach ( async function ( ) {
410
- client = this . configuration . newClient ( ) ;
413
+ client = this . configuration . newClient ( { } , { monitorCommands : true } ) ;
414
+ client . on ( 'commandStarted' , filterForCommands ( 'killCursors' , commands ) ) ;
411
415
412
416
collection = client . db ( 'abstract_cursor_integration' ) . collection ( 'test' ) ;
413
417
@@ -472,30 +476,48 @@ describe('class AbstractCursor', function () {
472
476
} ) ;
473
477
} ) ;
474
478
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
+ {
485
491
configureFailPoint : 'failCommand' ,
486
492
mode : { times : 1 } ,
487
493
data : {
488
494
failCommands : [ 'getMore' ] ,
489
495
blockConnection : true ,
490
496
blockTimeMS : 5000
491
497
}
492
- } as FailPoint ) ;
498
+ } ,
499
+ uri
500
+ ) ;
501
+ } ) ;
493
502
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 ( ) {
494
516
const cursor = collection . find (
495
517
{ } ,
496
518
{
497
519
timeoutContext : context ,
498
- timeoutMS : 1000 ,
520
+ timeoutMS : 150 ,
499
521
timeoutMode : CursorTimeoutMode . LIFETIME ,
500
522
batchSize : 1
501
523
}
@@ -504,7 +526,6 @@ describe('class AbstractCursor', function () {
504
526
const error = await cursor . toArray ( ) . catch ( e => e ) ;
505
527
506
528
expect ( error ) . to . be . instanceof ( MongoOperationTimeoutError ) ;
507
- // @ts -expect-error We know we have a CSOT timeout context but TS does not.
508
529
expect ( context . timeoutContext . remainingTimeMS ) . to . be . lessThan ( 0 ) ;
509
530
}
510
531
) ;
0 commit comments