@@ -16,6 +16,8 @@ import {
16
16
BSON ,
17
17
Collection ,
18
18
CSOTTimeoutContext ,
19
+ CursorTimeoutContext ,
20
+ type FindOptions ,
19
21
Int32 ,
20
22
Long ,
21
23
MongoClient ,
@@ -484,26 +486,29 @@ describe('StateMachine', function () {
484
486
} ) ;
485
487
486
488
context ( 'when StateMachine.fetchKeys() is passed a `CSOTimeoutContext`' , function ( ) {
487
- it ( 'collection.find runs with its timeoutMS property set to remainingTimeMS ' , async function ( ) {
488
- const timeoutContext = new CSOTTimeoutContext ( {
489
+ it ( 'collection.find uses the provided timeout context ' , async function ( ) {
490
+ const context = new CSOTTimeoutContext ( {
489
491
timeoutMS : 500 ,
490
492
serverSelectionTimeoutMS : 30000
491
493
} ) ;
492
- await sleep ( 300 ) ;
494
+
493
495
await stateMachine
494
- . fetchKeys ( client , 'keyVault' , BSON . serialize ( { a : 1 } ) , timeoutContext )
496
+ . fetchKeys ( client , 'keyVault' , BSON . serialize ( { a : 1 } ) , context )
495
497
. catch ( e => squashError ( e ) ) ;
496
- expect ( findSpy . getCalls ( ) [ 0 ] . args [ 1 ] . timeoutMS ) . to . not . be . undefined ;
497
- expect ( findSpy . getCalls ( ) [ 0 ] . args [ 1 ] . timeoutMS ) . to . be . lessThanOrEqual ( 205 ) ;
498
+
499
+ const { timeoutContext } = findSpy . getCalls ( ) [ 0 ] . args [ 1 ] as FindOptions ;
500
+ expect ( timeoutContext ) . to . be . instanceOf ( CursorTimeoutContext ) ;
501
+ expect ( timeoutContext . timeoutContext ) . to . equal ( context ) ;
498
502
} ) ;
499
503
} ) ;
500
504
501
505
context ( 'when StateMachine.fetchKeys() is not passed a `CSOTimeoutContext`' , function ( ) {
502
- it ( 'collection.find runs with an undefined timeoutMS property ' , async function ( ) {
506
+ it ( 'a timeoutContext is not provided to the find cursor ' , async function ( ) {
503
507
await stateMachine
504
508
. fetchKeys ( client , 'keyVault' , BSON . serialize ( { a : 1 } ) )
505
509
. catch ( e => squashError ( e ) ) ;
506
- expect ( findSpy . getCalls ( ) [ 0 ] . args [ 1 ] . timeoutMS ) . to . be . undefined ;
510
+ const { timeoutContext } = findSpy . getCalls ( ) [ 0 ] . args [ 1 ] as FindOptions ;
511
+ expect ( timeoutContext ) . to . be . undefined ;
507
512
} ) ;
508
513
} ) ;
509
514
} ) ;
@@ -564,29 +569,31 @@ describe('StateMachine', function () {
564
569
context (
565
570
'when StateMachine.fetchCollectionInfo() is passed a `CSOTimeoutContext`' ,
566
571
function ( ) {
567
- it ( 'listCollections runs with its timeoutMS property set to remainingTimeMS ' , async function ( ) {
568
- const timeoutContext = new CSOTTimeoutContext ( {
572
+ it ( 'listCollections uses the provided timeoutContext ' , async function ( ) {
573
+ const context = new CSOTTimeoutContext ( {
569
574
timeoutMS : 500 ,
570
575
serverSelectionTimeoutMS : 30000
571
576
} ) ;
572
577
await sleep ( 300 ) ;
573
578
await stateMachine
574
- . fetchCollectionInfo ( client , 'keyVault' , BSON . serialize ( { a : 1 } ) , timeoutContext )
579
+ . fetchCollectionInfo ( client , 'keyVault' , BSON . serialize ( { a : 1 } ) , context )
575
580
. catch ( e => squashError ( e ) ) ;
576
- expect ( listCollectionsSpy . getCalls ( ) [ 0 ] . args [ 1 ] . timeoutMS ) . to . not . be . undefined ;
577
- expect ( listCollectionsSpy . getCalls ( ) [ 0 ] . args [ 1 ] . timeoutMS ) . to . be . lessThanOrEqual ( 205 ) ;
581
+ const [ _filter , { timeoutContext } ] = listCollectionsSpy . getCalls ( ) [ 0 ] . args ;
582
+ expect ( timeoutContext ) . to . exist ;
583
+ expect ( timeoutContext . timeoutContext ) . to . equal ( context ) ;
578
584
} ) ;
579
585
}
580
586
) ;
581
587
582
588
context (
583
589
'when StateMachine.fetchCollectionInfo() is not passed a `CSOTimeoutContext`' ,
584
590
function ( ) {
585
- it ( 'listCollections runs with an undefined timeoutMS property ' , async function ( ) {
591
+ it ( 'no timeoutContext is provided to listCollections ' , async function ( ) {
586
592
await stateMachine
587
593
. fetchCollectionInfo ( client , 'keyVault' , BSON . serialize ( { a : 1 } ) )
588
594
. catch ( e => squashError ( e ) ) ;
589
- expect ( listCollectionsSpy . getCalls ( ) [ 0 ] . args [ 1 ] . timeoutMS ) . to . be . undefined ;
595
+ const [ _filter , { timeoutContext } ] = listCollectionsSpy . getCalls ( ) [ 0 ] . args ;
596
+ expect ( timeoutContext ) . not . to . exist ;
590
597
} ) ;
591
598
}
592
599
) ;
0 commit comments