55 * Drivers SHOULD implement these if it is possible to do so using the driver's existing test infrastructure.
66 */
77
8+ import { expect } from 'chai' ;
9+ import * as sinon from 'sinon' ;
10+
11+ import { ConnectionPool , type MongoClient , Timeout , Topology } from '../../mongodb' ;
12+
813// TODO(NODE-5824): Implement CSOT prose tests
9- describe . skip ( 'CSOT spec unit tests' , ( ) => {
10- context ( 'Operations should ignore waitQueueTimeoutMS if timeoutMS is also set.' , ( ) => { } ) ;
14+ describe ( 'CSOT spec unit tests' , function ( ) {
15+ let client : MongoClient ;
1116
12- context (
13- 'If timeoutMS is set for an operation, the remaining timeoutMS value should apply to connection checkout after a server has been selected.' ,
14- ( ) => { }
15- ) ;
17+ afterEach ( async function ( ) {
18+ sinon . restore ( ) ;
19+ await client ?. close ( ) ;
20+ } ) ;
1621
17- context (
18- 'If timeoutMS is not set for an operation, waitQueueTimeoutMS should apply to connection checkout after a server has been selected.' ,
19- ( ) => { }
20- ) ;
22+ it ( 'Operations should ignore waitQueueTimeoutMS if timeoutMS is also set.' , async function ( ) {
23+ client = this . configuration . newClient ( { waitQueueTimeoutMS : 10_000 , timeoutMS : 200 } ) ;
24+ sinon . spy ( Timeout , 'expires' ) ;
25+
26+ await client . db ( 'db' ) . collection ( 'collection' ) . insertOne ( { x : 1 } ) ;
27+
28+ expect ( Timeout . expires ) . to . have . been . calledWith ( 200 ) ;
29+ expect ( Timeout . expires ) . to . not . have . been . calledWith ( 10_000 ) ;
30+ } ) ;
31+
32+ it ( 'If timeoutMS is set for an operation, the remaining timeoutMS value should apply to connection checkout after a server has been selected.' , async function ( ) {
33+ client = this . configuration . newClient ( { timeoutMS : 200 } ) ;
34+ const expiresSpy = sinon . spy ( Timeout , 'expires' ) ;
35+ const remainingTimeSpy = sinon . spy ( Timeout . prototype , 'remainingTime' , [ 'get' ] ) ;
36+
37+ await client . db ( 'db' ) . collection ( 'collection' ) . insertOne ( { x : 1 } ) ;
38+ const getterFirstCall = remainingTimeSpy . get . firstCall ;
39+
40+ expect ( expiresSpy . lastCall . args [ 0 ] ) . to . be . approximately ( getterFirstCall . returnValue , 1 ) ;
41+ } ) ;
42+
43+ it ( 'If timeoutMS is not set for an operation, waitQueueTimeoutMS should apply to connection checkout after a server has been selected.' , async function ( ) {
44+ client = this . configuration . newClient ( { waitQueueTimeoutMS : 123456 } ) ;
45+
46+ const checkoutSpy = sinon . spy ( ConnectionPool . prototype , 'checkOut' ) ;
47+ const selectServerSpy = sinon . spy ( Topology . prototype , 'selectServer' ) ;
48+ const expiresSpy = sinon . spy ( Timeout , 'expires' ) ;
49+
50+ await client . db ( 'db' ) . collection ( 'collection' ) . insertOne ( { x : 1 } ) ;
51+ expect ( checkoutSpy ) . to . have . been . calledAfter ( selectServerSpy ) ;
52+
53+ expect ( expiresSpy ) . to . have . been . calledWith ( 123456 ) ;
54+ } ) ;
2155
2256 context (
2357 'If a new connection is required to execute an operation, min(remaining computedServerSelectionTimeout, connectTimeoutMS) should apply to socket establishment.' ,
@@ -29,23 +63,24 @@ describe.skip('CSOT spec unit tests', () => {
2963 ( ) => { }
3064 ) ;
3165
32- context (
66+ context . skip (
3367 'If timeoutMS is unset, operations fail after two non-consecutive socket timeouts.' ,
3468 ( ) => { }
35- ) ;
69+ ) . skipReason =
70+ 'TODO(NODE-5682): Add CSOT support for socket read/write at the connection layer for CRUD APIs' ;
3671
37- context (
72+ context . skip (
3873 'The remaining timeoutMS value should apply to HTTP requests against KMS servers for CSFLE.' ,
3974 ( ) => { }
40- ) ;
75+ ) . skipReason = 'TODO(NODE-5686): Add CSOT support to client side encryption' ;
4176
42- context (
77+ context . skip (
4378 'The remaining timeoutMS value should apply to commands sent to mongocryptd as part of automatic encryption.' ,
4479 ( ) => { }
45- ) ;
80+ ) . skipReason = 'TODO(NODE-5686): Add CSOT support to client side encryption' ;
4681
47- context (
82+ context . skip (
4883 'When doing minPoolSize maintenance, connectTimeoutMS is used as the timeout for socket establishment.' ,
4984 ( ) => { }
50- ) ;
85+ ) . skipReason = 'TODO(NODE-6091): Implement CSOT logic for Background Connection Pooling' ;
5186} ) ;
0 commit comments