@@ -597,112 +597,118 @@ describe('CSOT spec prose tests', function () {
597
597
'TODO(DRIVERS-2347): Requires this ticket to be implemented before we can assert on connection CSOT behaviour' ;
598
598
} ) ;
599
599
600
- describe (
601
- '9. endSession' ,
602
- { requires : { topology : [ 'replicaset' , 'sharded' , 'load-balanced' ] } } ,
603
- ( ) => {
604
- /**
605
- * This test MUST only be run against replica sets and sharded clusters with server version 4.4 or higher. It MUST be
606
- * run three times: once with the timeout specified via the MongoClient `timeoutMS` option, once with the timeout
607
- * specified via the ClientSession `defaultTimeoutMS` option, and once more with the timeout specified via the
608
- * `timeoutMS` option for the `endSession` operation. In all cases, the timeout MUST be set to 10 milliseconds.
609
- *
610
- * 1. Using `internalClient`, drop the `db.coll` collection.
611
- * 1. Using `internalClient`, set the following fail point:
612
- * ```js
613
- * {
614
- * configureFailPoint: failCommand,
615
- * mode: { times: 1 },
616
- * data: {
617
- * failCommands: ["abortTransaction"],
618
- * blockConnection: true,
619
- * blockTimeMS: 15
620
- * }
621
- * }
622
- * ```
623
- * 1. Create a new MongoClient (referred to as `client`) and an explicit ClientSession derived from that MongoClient (referred to as `session`).
624
- * 1. Execute the following code:
625
- * ```ts
626
- * coll = client.database("db").collection("coll")
627
- * session.start_transaction()
628
- * coll.insert_one({x: 1}, session=session)
629
- * ```
630
- * 1. Using `session`, execute `session.end_session`
631
- * - Expect this to fail with a timeout error after no more than 15ms.
632
- */
633
- const failpoint : FailPoint = {
634
- configureFailPoint : 'failCommand' ,
635
- mode : { times : 1 } ,
636
- data : {
637
- failCommands : [ 'abortTransaction' ] ,
638
- blockConnection : true ,
639
- blockTimeMS : 60
640
- }
641
- } ;
642
-
643
- beforeEach ( async function ( ) {
644
- if ( ! semver . satisfies ( this . configuration . version , '>=4.4' ) ) {
645
- this . skipReason = 'Requires server version 4.4+' ;
646
- this . skip ( ) ;
647
- }
648
- const internalClient = this . configuration . newClient ( ) ;
649
- await internalClient
650
- . db ( 'db' )
651
- . collection ( 'coll' )
652
- . drop ( )
653
- . catch ( ( ) => null ) ;
654
- await internalClient . db ( 'admin' ) . command ( failpoint ) ;
655
- await internalClient . close ( ) ;
656
- } ) ;
600
+ describe ( '9. endSession' , ( ) => {
601
+ /**
602
+ * This test MUST only be run against replica sets and sharded clusters with server version 4.4 or higher. It MUST be
603
+ * run three times: once with the timeout specified via the MongoClient `timeoutMS` option, once with the timeout
604
+ * specified via the ClientSession `defaultTimeoutMS` option, and once more with the timeout specified via the
605
+ * `timeoutMS` option for the `endSession` operation. In all cases, the timeout MUST be set to 10 milliseconds.
606
+ *
607
+ * 1. Using `internalClient`, drop the `db.coll` collection.
608
+ * 1. Using `internalClient`, set the following fail point:
609
+ * ```js
610
+ * {
611
+ * configureFailPoint: failCommand,
612
+ * mode: { times: 1 },
613
+ * data: {
614
+ * failCommands: ["abortTransaction"],
615
+ * blockConnection: true,
616
+ * blockTimeMS: 15
617
+ * }
618
+ * }
619
+ * ```
620
+ * 1. Create a new MongoClient (referred to as `client`) and an explicit ClientSession derived from that MongoClient (referred to as `session`).
621
+ * 1. Execute the following code:
622
+ * ```ts
623
+ * coll = client.database("db").collection("coll")
624
+ * session.start_transaction()
625
+ * coll.insert_one({x: 1}, session=session)
626
+ * ```
627
+ * 1. Using `session`, execute `session.end_session`
628
+ * - Expect this to fail with a timeout error after no more than 15ms.
629
+ */
630
+ const failpoint : FailPoint = {
631
+ configureFailPoint : 'failCommand' ,
632
+ mode : { times : 1 } ,
633
+ data : {
634
+ failCommands : [ 'abortTransaction' ] ,
635
+ blockConnection : true ,
636
+ blockTimeMS : 60
637
+ }
638
+ } ;
639
+
640
+ beforeEach ( async function ( ) {
641
+ if ( ! semver . satisfies ( this . configuration . version , '>=4.4' ) ) {
642
+ this . skipReason = 'Requires server version 4.4+' ;
643
+ this . skip ( ) ;
644
+ }
645
+
646
+ if (
647
+ ! [ 'Sharded' , 'ReplicaSetWithPrimary' , 'ReplicaSetNoPrimary' ] . includes (
648
+ this . configuration . topologyType
649
+ )
650
+ ) {
651
+ this . skipReason = 'Requires replicaset or sharded clusters' ;
652
+ this . skip ( ) ;
653
+ }
654
+
655
+ const internalClient = this . configuration . newClient ( ) ;
656
+ await internalClient
657
+ . db ( 'db' )
658
+ . collection ( 'coll' )
659
+ . drop ( )
660
+ . catch ( ( ) => null ) ;
661
+ await internalClient . db ( 'admin' ) . command ( failpoint ) ;
662
+ await internalClient . close ( ) ;
663
+ } ) ;
657
664
658
- let client : MongoClient ;
665
+ let client : MongoClient ;
659
666
660
- afterEach ( async function ( ) {
661
- if ( semver . satisfies ( this . configuration . version , '>=4.4' ) ) {
662
- const internalClient = this . configuration . newClient ( ) ;
663
- await internalClient . db ( 'admin' ) . command ( { ...failpoint , mode : 'off' } ) ;
664
- await internalClient . close ( ) ;
665
- }
666
- await client ?. close ( ) ;
667
- } ) ;
667
+ afterEach ( async function ( ) {
668
+ if ( semver . satisfies ( this . configuration . version , '>=4.4' ) ) {
669
+ const internalClient = this . configuration . newClient ( ) ;
670
+ await internalClient . db ( 'admin' ) . command ( { ...failpoint , mode : 'off' } ) ;
671
+ await internalClient . close ( ) ;
672
+ }
673
+ await client ?. close ( ) ;
674
+ } ) ;
668
675
669
- describe ( 'when timeoutMS is provided to the client' , ( ) => {
670
- it ( 'throws a timeout error from endSession' , async function ( ) {
671
- client = this . configuration . newClient ( { timeoutMS : 50 , monitorCommands : true } ) ;
672
- const coll = client . db ( 'db' ) . collection ( 'coll' ) ;
673
- const session = client . startSession ( ) ;
674
- session . startTransaction ( ) ;
675
- await coll . insertOne ( { x : 1 } , { session } ) ;
676
- const error = await session . endSession ( ) . catch ( error => error ) ;
677
- expect ( error ) . to . be . instanceOf ( MongoOperationTimeoutError ) ;
678
- } ) ;
676
+ describe ( 'when timeoutMS is provided to the client' , ( ) => {
677
+ it ( 'throws a timeout error from endSession' , async function ( ) {
678
+ client = this . configuration . newClient ( { timeoutMS : 50 , monitorCommands : true } ) ;
679
+ const coll = client . db ( 'db' ) . collection ( 'coll' ) ;
680
+ const session = client . startSession ( ) ;
681
+ session . startTransaction ( ) ;
682
+ await coll . insertOne ( { x : 1 } , { session } ) ;
683
+ const error = await session . endSession ( ) . catch ( error => error ) ;
684
+ expect ( error ) . to . be . instanceOf ( MongoOperationTimeoutError ) ;
679
685
} ) ;
686
+ } ) ;
680
687
681
- describe ( 'when defaultTimeoutMS is provided to startSession' , ( ) => {
682
- it ( 'throws a timeout error from endSession' , async function ( ) {
683
- client = this . configuration . newClient ( ) ;
684
- const coll = client . db ( 'db' ) . collection ( 'coll' ) ;
685
- const session = client . startSession ( { defaultTimeoutMS : 50 } ) ;
686
- session . startTransaction ( ) ;
687
- await coll . insertOne ( { x : 1 } , { session } ) ;
688
- const error = await session . endSession ( ) . catch ( error => error ) ;
689
- expect ( error ) . to . be . instanceOf ( MongoOperationTimeoutError ) ;
690
- } ) ;
688
+ describe ( 'when defaultTimeoutMS is provided to startSession' , ( ) => {
689
+ it ( 'throws a timeout error from endSession' , async function ( ) {
690
+ client = this . configuration . newClient ( ) ;
691
+ const coll = client . db ( 'db' ) . collection ( 'coll' ) ;
692
+ const session = client . startSession ( { defaultTimeoutMS : 50 } ) ;
693
+ session . startTransaction ( ) ;
694
+ await coll . insertOne ( { x : 1 } , { session } ) ;
695
+ const error = await session . endSession ( ) . catch ( error => error ) ;
696
+ expect ( error ) . to . be . instanceOf ( MongoOperationTimeoutError ) ;
691
697
} ) ;
698
+ } ) ;
692
699
693
- describe ( 'when timeoutMS is provided to endSession' , ( ) => {
694
- it ( 'throws a timeout error from endSession' , async function ( ) {
695
- client = this . configuration . newClient ( ) ;
696
- const coll = client . db ( 'db' ) . collection ( 'coll' ) ;
697
- const session = client . startSession ( ) ;
698
- session . startTransaction ( ) ;
699
- await coll . insertOne ( { x : 1 } , { session } ) ;
700
- const error = await session . endSession ( { timeoutMS : 50 } ) . catch ( error => error ) ;
701
- expect ( error ) . to . be . instanceOf ( MongoOperationTimeoutError ) ;
702
- } ) ;
700
+ describe ( 'when timeoutMS is provided to endSession' , ( ) => {
701
+ it ( 'throws a timeout error from endSession' , async function ( ) {
702
+ client = this . configuration . newClient ( ) ;
703
+ const coll = client . db ( 'db' ) . collection ( 'coll' ) ;
704
+ const session = client . startSession ( ) ;
705
+ session . startTransaction ( ) ;
706
+ await coll . insertOne ( { x : 1 } , { session } ) ;
707
+ const error = await session . endSession ( { timeoutMS : 50 } ) . catch ( error => error ) ;
708
+ expect ( error ) . to . be . instanceOf ( MongoOperationTimeoutError ) ;
703
709
} ) ;
704
- }
705
- ) ;
710
+ } ) ;
711
+ } ) ;
706
712
707
713
describe (
708
714
'10. Convenient Transactions' ,
0 commit comments