5
5
* Drivers SHOULD implement these if it is possible to do so using the driver's existing test infrastructure.
6
6
*/
7
7
8
+ import { expect } from 'chai' ;
9
+ import * as sinon from 'sinon' ;
10
+
11
+ import { ConnectionPool , type MongoClient , Timeout , Topology } from '../../mongodb' ;
12
+
8
13
// 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 ;
11
16
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
+ } ) ;
16
21
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
+ } ) ;
21
55
22
56
context (
23
57
'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', () => {
29
63
( ) => { }
30
64
) ;
31
65
32
- context (
66
+ context . skip (
33
67
'If timeoutMS is unset, operations fail after two non-consecutive socket timeouts.' ,
34
68
( ) => { }
35
- ) ;
69
+ ) . skipReason =
70
+ 'TODO(NODE-5682): Add CSOT support for socket read/write at the connection layer for CRUD APIs' ;
36
71
37
- context (
72
+ context . skip (
38
73
'The remaining timeoutMS value should apply to HTTP requests against KMS servers for CSFLE.' ,
39
74
( ) => { }
40
- ) ;
75
+ ) . skipReason = 'TODO(NODE-5686): Add CSOT support to client side encryption' ;
41
76
42
- context (
77
+ context . skip (
43
78
'The remaining timeoutMS value should apply to commands sent to mongocryptd as part of automatic encryption.' ,
44
79
( ) => { }
45
- ) ;
80
+ ) . skipReason = 'TODO(NODE-5686): Add CSOT support to client side encryption' ;
46
81
47
- context (
82
+ context . skip (
48
83
'When doing minPoolSize maintenance, connectTimeoutMS is used as the timeout for socket establishment.' ,
49
84
( ) => { }
50
- ) ;
85
+ ) . skipReason = 'TODO(NODE-6091): Implement CSOT logic for Background Connection Pooling' ;
51
86
} ) ;
0 commit comments