@@ -16,6 +16,8 @@ import {
1616 BSON ,
1717 Collection ,
1818 CSOTTimeoutContext ,
19+ CursorTimeoutContext ,
20+ type FindOptions ,
1921 Int32 ,
2022 Long ,
2123 MongoClient ,
@@ -484,26 +486,29 @@ describe('StateMachine', function () {
484486 } ) ;
485487
486488 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 ( {
489491 timeoutMS : 500 ,
490492 serverSelectionTimeoutMS : 30000
491493 } ) ;
492- await sleep ( 300 ) ;
494+
493495 await stateMachine
494- . fetchKeys ( client , 'keyVault' , BSON . serialize ( { a : 1 } ) , timeoutContext )
496+ . fetchKeys ( client , 'keyVault' , BSON . serialize ( { a : 1 } ) , context )
495497 . 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 ) ;
498502 } ) ;
499503 } ) ;
500504
501505 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 ( ) {
503507 await stateMachine
504508 . fetchKeys ( client , 'keyVault' , BSON . serialize ( { a : 1 } ) )
505509 . 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 ;
507512 } ) ;
508513 } ) ;
509514 } ) ;
@@ -564,29 +569,31 @@ describe('StateMachine', function () {
564569 context (
565570 'when StateMachine.fetchCollectionInfo() is passed a `CSOTimeoutContext`' ,
566571 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 ( {
569574 timeoutMS : 500 ,
570575 serverSelectionTimeoutMS : 30000
571576 } ) ;
572577 await sleep ( 300 ) ;
573578 await stateMachine
574- . fetchCollectionInfo ( client , 'keyVault' , BSON . serialize ( { a : 1 } ) , timeoutContext )
579+ . fetchCollectionInfo ( client , 'keyVault' , BSON . serialize ( { a : 1 } ) , context )
575580 . 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 ) ;
578584 } ) ;
579585 }
580586 ) ;
581587
582588 context (
583589 'when StateMachine.fetchCollectionInfo() is not passed a `CSOTimeoutContext`' ,
584590 function ( ) {
585- it ( 'listCollections runs with an undefined timeoutMS property ' , async function ( ) {
591+ it ( 'no timeoutContext is provided to listCollections ' , async function ( ) {
586592 await stateMachine
587593 . fetchCollectionInfo ( client , 'keyVault' , BSON . serialize ( { a : 1 } ) )
588594 . 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 ;
590597 } ) ;
591598 }
592599 ) ;
0 commit comments