@@ -16,7 +16,10 @@ import {
1616 BSON ,
1717 Collection ,
1818 CSOTTimeoutContext ,
19+ CursorTimeoutContext ,
20+ type FindOptions ,
1921 Int32 ,
22+ type ListCollectionsOptions ,
2023 Long ,
2124 MongoClient ,
2225 serialize ,
@@ -484,26 +487,29 @@ describe('StateMachine', function () {
484487 } ) ;
485488
486489 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 ( {
490+ it ( 'collection.find uses the provided timeout context ' , async function ( ) {
491+ const context = new CSOTTimeoutContext ( {
489492 timeoutMS : 500 ,
490493 serverSelectionTimeoutMS : 30000
491494 } ) ;
492- await sleep ( 300 ) ;
495+
493496 await stateMachine
494- . fetchKeys ( client , 'keyVault' , BSON . serialize ( { a : 1 } ) , timeoutContext )
497+ . fetchKeys ( client , 'keyVault' , BSON . serialize ( { a : 1 } ) , context )
495498 . 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 ) ;
499+
500+ const { timeoutContext } = findSpy . getCalls ( ) [ 0 ] . args [ 1 ] as FindOptions ;
501+ expect ( timeoutContext ) . to . be . instanceOf ( CursorTimeoutContext ) ;
502+ expect ( timeoutContext . timeoutContext ) . to . equal ( context ) ;
498503 } ) ;
499504 } ) ;
500505
501506 context ( 'when StateMachine.fetchKeys() is not passed a `CSOTimeoutContext`' , function ( ) {
502- it ( 'collection.find runs with an undefined timeoutMS property ' , async function ( ) {
507+ it ( 'a timeoutContext is not provided to the find cursor ' , async function ( ) {
503508 await stateMachine
504509 . fetchKeys ( client , 'keyVault' , BSON . serialize ( { a : 1 } ) )
505510 . catch ( e => squashError ( e ) ) ;
506- expect ( findSpy . getCalls ( ) [ 0 ] . args [ 1 ] . timeoutMS ) . to . be . undefined ;
511+ const { timeoutContext } = findSpy . getCalls ( ) [ 0 ] . args [ 1 ] as FindOptions ;
512+ expect ( timeoutContext ) . to . be . undefined ;
507513 } ) ;
508514 } ) ;
509515 } ) ;
@@ -564,29 +570,35 @@ describe('StateMachine', function () {
564570 context (
565571 'when StateMachine.fetchCollectionInfo() is passed a `CSOTimeoutContext`' ,
566572 function ( ) {
567- it ( 'listCollections runs with its timeoutMS property set to remainingTimeMS ' , async function ( ) {
568- const timeoutContext = new CSOTTimeoutContext ( {
573+ it ( 'listCollections uses the provided timeoutContext ' , async function ( ) {
574+ const context = new CSOTTimeoutContext ( {
569575 timeoutMS : 500 ,
570576 serverSelectionTimeoutMS : 30000
571577 } ) ;
572- await sleep ( 300 ) ;
578+
573579 await stateMachine
574- . fetchCollectionInfo ( client , 'keyVault' , BSON . serialize ( { a : 1 } ) , timeoutContext )
580+ . fetchCollectionInfo ( client , 'keyVault' , BSON . serialize ( { a : 1 } ) , context )
575581 . 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 ) ;
582+
583+ const { timeoutContext } = listCollectionsSpy . getCalls ( ) [ 0 ]
584+ . args [ 1 ] as ListCollectionsOptions ;
585+ expect ( timeoutContext ) . to . be . instanceOf ( CursorTimeoutContext ) ;
586+ expect ( timeoutContext . timeoutContext ) . to . equal ( context ) ;
578587 } ) ;
579588 }
580589 ) ;
581590
582591 context (
583592 'when StateMachine.fetchCollectionInfo() is not passed a `CSOTimeoutContext`' ,
584593 function ( ) {
585- it ( 'listCollections runs with an undefined timeoutMS property ' , async function ( ) {
594+ it ( 'no timeoutContext is provided to listCollections ' , async function ( ) {
586595 await stateMachine
587596 . fetchCollectionInfo ( client , 'keyVault' , BSON . serialize ( { a : 1 } ) )
588597 . catch ( e => squashError ( e ) ) ;
589- expect ( listCollectionsSpy . getCalls ( ) [ 0 ] . args [ 1 ] . timeoutMS ) . to . be . undefined ;
598+
599+ const { timeoutContext } = listCollectionsSpy . getCalls ( ) [ 0 ]
600+ . args [ 1 ] as ListCollectionsOptions ;
601+ expect ( timeoutContext ) . to . be . undefined ;
590602 } ) ;
591603 }
592604 ) ;
0 commit comments