11/* Specification prose tests */
22
3+ import { expect } from 'chai' ;
4+
5+ import { MongoClient , MongoServerSelectionError , now } from '../../mongodb' ;
6+
37// TODO(NODE-5824): Implement CSOT prose tests
4- describe . skip ( 'CSOT spec prose tests' , ( ) => {
5- context ( '1. Multi-batch writes' , ( ) => {
8+ describe ( 'CSOT spec prose tests' , ( ) => {
9+ context . skip ( '1. Multi-batch writes' , ( ) => {
610 /**
711 * This test MUST only run against standalones on server versions 4.4 and higher.
812 * The `insertMany` call takes an exceedingly long time on replicasets and sharded
@@ -31,7 +35,7 @@ describe.skip('CSOT spec prose tests', () => {
3135 */
3236 } ) ;
3337
34- context ( '2. maxTimeMS is not set for commands sent to mongocryptd' , ( ) => {
38+ context . skip ( '2. maxTimeMS is not set for commands sent to mongocryptd' , ( ) => {
3539 /**
3640 * This test MUST only be run against enterprise server versions 4.2 and higher.
3741 *
@@ -42,7 +46,7 @@ describe.skip('CSOT spec prose tests', () => {
4246 */
4347 } ) ;
4448
45- context ( '3. ClientEncryption' , ( ) => {
49+ context . skip ( '3. ClientEncryption' , ( ) => {
4650 /**
4751 * Each test under this category MUST only be run against server versions 4.4 and higher. In these tests,
4852 * `LOCAL_MASTERKEY` refers to the following base64:
@@ -132,7 +136,7 @@ describe.skip('CSOT spec prose tests', () => {
132136 } ) ;
133137 } ) ;
134138
135- context ( '4. Background Connection Pooling' , ( ) => {
139+ context . skip ( '4. Background Connection Pooling' , ( ) => {
136140 /**
137141 * The tests in this section MUST only be run if the server version is 4.4 or higher and the URI has authentication
138142 * fields (i.e. a username and password). Each test in this section requires drivers to create a MongoClient and then wait
@@ -192,7 +196,7 @@ describe.skip('CSOT spec prose tests', () => {
192196 } ) ;
193197 } ) ;
194198
195- context ( '5. Blocking Iteration Methods' , ( ) => {
199+ context . skip ( '5. Blocking Iteration Methods' , ( ) => {
196200 /**
197201 * Tests in this section MUST only be run against server versions 4.4 and higher and only apply to drivers that have a
198202 * blocking method for cursor iteration that executes `getMore` commands in a loop until a document is available or an
@@ -251,7 +255,7 @@ describe.skip('CSOT spec prose tests', () => {
251255 } ) ;
252256 } ) ;
253257
254- context ( '6. GridFS - Upload' , ( ) => {
258+ context . skip ( '6. GridFS - Upload' , ( ) => {
255259 /** Tests in this section MUST only be run against server versions 4.4 and higher. */
256260
257261 context ( 'uploads via openUploadStream can be timed out' , ( ) => {
@@ -306,7 +310,7 @@ describe.skip('CSOT spec prose tests', () => {
306310 } ) ;
307311 } ) ;
308312
309- context ( '7. GridFS - Download' , ( ) => {
313+ context . skip ( '7. GridFS - Download' , ( ) => {
310314 /**
311315 * This test MUST only be run against server versions 4.4 and higher.
312316 * 1. Using `internalClient`, drop and re-create the `db.fs.files` and `db.fs.chunks` collections.
@@ -351,42 +355,94 @@ describe.skip('CSOT spec prose tests', () => {
351355 } ) ;
352356
353357 context ( '8. Server Selection' , ( ) => {
354- context ( 'serverSelectionTimeoutMS honored if timeoutMS is not set' , ( ) => {
358+ it ( 'serverSelectionTimeoutMS honored if timeoutMS is not set' , async ( ) => {
355359 /**
356360 * 1. Create a MongoClient (referred to as `client`) with URI `mongodb://invalid/?serverSelectionTimeoutMS=10`.
357361 * 1. Using `client`, execute the command `{ ping: 1 }` against the `admin` database.
358362 * - Expect this to fail with a server selection timeout error after no more than 15ms.
359363 */
364+ const client = new MongoClient ( 'mongodb://invalid/?serverSelectionTimeoutMS=10' ) ;
365+ let duration : number ;
366+ const admin = client . db ( 'test' ) . admin ( ) ;
367+ const start = now ( ) ;
368+ const maybeError = await admin
369+ . ping ( )
370+ . then (
371+ ( ) => null ,
372+ e => e
373+ )
374+ . finally ( ( ) => {
375+ duration = now ( ) - start ;
376+ } ) ;
377+
378+ expect ( maybeError ) . to . be . instanceof ( MongoServerSelectionError ) ;
379+ expect ( duration ) . to . be . lte ( 15 ) ;
360380 } ) ;
361381
362- context (
363- "timeoutMS honored for server selection if it's lower than serverSelectionTimeoutMS" ,
364- ( ) => {
365- /**
366- * 1. Create a MongoClient (referred to as `client`) with URI `mongodb://invalid/?timeoutMS=10&serverSelectionTimeoutMS=20`.
367- * 1. Using `client`, run the command `{ ping: 1 }` against the `admin` database.
368- * - Expect this to fail with a server selection timeout error after no more than 15ms.
369- */
370- }
371- ) ;
382+ it ( "timeoutMS honored for server selection if it's lower than serverSelectionTimeoutMS" , async ( ) => {
383+ /**
384+ * 1. Create a MongoClient (referred to as `client`) with URI `mongodb://invalid/?timeoutMS=10&serverSelectionTimeoutMS=20`.
385+ * 1. Using `client`, run the command `{ ping: 1 }` against the `admin` database.
386+ * - Expect this to fail with a server selection timeout error after no more than 15ms.
387+ */
388+ const client = new MongoClient ( 'mongodb://invalid/?timeoutMS=10&serverSelectionTimeoutMS=20' ) ;
389+ const start = now ( ) ;
390+ const maybeError = await client
391+ . db ( 'test' )
392+ . admin ( )
393+ . command ( { ping : 1 } )
394+ . then (
395+ ( ) => null ,
396+ e => e
397+ ) ;
398+ const end = now ( ) ;
372399
373- context (
374- "serverSelectionTimeoutMS honored for server selection if it's lower than timeoutMS" ,
375- ( ) => {
376- /**
377- * 1. Create a MongoClient (referred to as `client`) with URI `mongodb://invalid/?timeoutMS=20&serverSelectionTimeoutMS=10`.
378- * 1. Using `client`, run the command `{ ping: 1 }` against the `admin` database.
379- * - Expect this to fail with a server selection timeout error after no more than 15ms.
380- */
381- }
382- ) ;
400+ expect ( maybeError ) . to . be . instanceof ( MongoServerSelectionError ) ;
401+ expect ( end - start ) . to . be . lte ( 15 ) ;
402+ } ) ;
403+
404+ it ( "serverSelectionTimeoutMS honored for server selection if it's lower than timeoutMS" , async ( ) => {
405+ /**
406+ * 1. Create a MongoClient (referred to as `client`) with URI `mongodb://invalid/?timeoutMS=20&serverSelectionTimeoutMS=10`.
407+ * 1. Using `client`, run the command `{ ping: 1 }` against the `admin` database.
408+ * - Expect this to fail with a server selection timeout error after no more than 15ms.
409+ */
410+ const client = new MongoClient ( 'mongodb://invalid/?timeoutMS=20&serverSelectionTimeoutMS=10' ) ;
411+ const start = now ( ) ;
412+ const maybeError = await client
413+ . db ( 'test' )
414+ . admin ( )
415+ . command ( { ping : 1 } )
416+ . then (
417+ ( ) => null ,
418+ e => e
419+ ) ;
420+ const end = now ( ) ;
383421
384- context ( 'serverSelectionTimeoutMS honored for server selection if timeoutMS=0' , ( ) => {
422+ expect ( maybeError ) . to . be . instanceof ( MongoServerSelectionError ) ;
423+ expect ( end - start ) . to . be . lte ( 15 ) ;
424+ } ) ;
425+
426+ it ( 'serverSelectionTimeoutMS honored for server selection if timeoutMS=0' , async ( ) => {
385427 /**
386428 * 1. Create a MongoClient (referred to as `client`) with URI `mongodb://invalid/?timeoutMS=0&serverSelectionTimeoutMS=10`.
387429 * 1. Using `client`, run the command `{ ping: 1 }` against the `admin` database.
388430 * - Expect this to fail with a server selection timeout error after no more than 15ms.
389431 */
432+ const client = new MongoClient ( 'mongodb://invalid/?timeoutMS=0&serverSelectionTimeoutMS=10' ) ;
433+ const start = now ( ) ;
434+ const maybeError = await client
435+ . db ( 'test' )
436+ . admin ( )
437+ . command ( { ping : 1 } )
438+ . then (
439+ ( ) => null ,
440+ e => e
441+ ) ;
442+ const end = now ( ) ;
443+
444+ expect ( maybeError ) . to . be . instanceof ( MongoServerSelectionError ) ;
445+ expect ( end - start ) . to . be . lte ( 15 ) ;
390446 } ) ;
391447
392448 context (
@@ -440,7 +496,7 @@ describe.skip('CSOT spec prose tests', () => {
440496 ) ;
441497 } ) ;
442498
443- context ( '9. endSession' , ( ) => {
499+ context . skip ( '9. endSession' , ( ) => {
444500 /**
445501 * This test MUST only be run against replica sets and sharded clusters with server version 4.4 or higher. It MUST be
446502 * run three times: once with the timeout specified via the MongoClient `timeoutMS` option, once with the timeout
@@ -472,7 +528,7 @@ describe.skip('CSOT spec prose tests', () => {
472528 */
473529 } ) ;
474530
475- context ( '10. Convenient Transactions' , ( ) => {
531+ context . skip ( '10. Convenient Transactions' , ( ) => {
476532 /** Tests in this section MUST only run against replica sets and sharded clusters with server versions 4.4 or higher. */
477533
478534 context ( 'timeoutMS is refreshed for abortTransaction if the callback fails' , ( ) => {
0 commit comments