1
1
/* Specification prose tests */
2
2
3
+ import { expect } from 'chai' ;
4
+
5
+ import { MongoClient , MongoServerSelectionError , now } from '../../mongodb' ;
6
+
3
7
// 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' , ( ) => {
6
10
/**
7
11
* This test MUST only run against standalones on server versions 4.4 and higher.
8
12
* The `insertMany` call takes an exceedingly long time on replicasets and sharded
@@ -31,7 +35,7 @@ describe.skip('CSOT spec prose tests', () => {
31
35
*/
32
36
} ) ;
33
37
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' , ( ) => {
35
39
/**
36
40
* This test MUST only be run against enterprise server versions 4.2 and higher.
37
41
*
@@ -42,7 +46,7 @@ describe.skip('CSOT spec prose tests', () => {
42
46
*/
43
47
} ) ;
44
48
45
- context ( '3. ClientEncryption' , ( ) => {
49
+ context . skip ( '3. ClientEncryption' , ( ) => {
46
50
/**
47
51
* Each test under this category MUST only be run against server versions 4.4 and higher. In these tests,
48
52
* `LOCAL_MASTERKEY` refers to the following base64:
@@ -132,7 +136,7 @@ describe.skip('CSOT spec prose tests', () => {
132
136
} ) ;
133
137
} ) ;
134
138
135
- context ( '4. Background Connection Pooling' , ( ) => {
139
+ context . skip ( '4. Background Connection Pooling' , ( ) => {
136
140
/**
137
141
* The tests in this section MUST only be run if the server version is 4.4 or higher and the URI has authentication
138
142
* 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', () => {
192
196
} ) ;
193
197
} ) ;
194
198
195
- context ( '5. Blocking Iteration Methods' , ( ) => {
199
+ context . skip ( '5. Blocking Iteration Methods' , ( ) => {
196
200
/**
197
201
* Tests in this section MUST only be run against server versions 4.4 and higher and only apply to drivers that have a
198
202
* 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', () => {
251
255
} ) ;
252
256
} ) ;
253
257
254
- context ( '6. GridFS - Upload' , ( ) => {
258
+ context . skip ( '6. GridFS - Upload' , ( ) => {
255
259
/** Tests in this section MUST only be run against server versions 4.4 and higher. */
256
260
257
261
context ( 'uploads via openUploadStream can be timed out' , ( ) => {
@@ -306,7 +310,7 @@ describe.skip('CSOT spec prose tests', () => {
306
310
} ) ;
307
311
} ) ;
308
312
309
- context ( '7. GridFS - Download' , ( ) => {
313
+ context . skip ( '7. GridFS - Download' , ( ) => {
310
314
/**
311
315
* This test MUST only be run against server versions 4.4 and higher.
312
316
* 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', () => {
351
355
} ) ;
352
356
353
357
context ( '8. Server Selection' , ( ) => {
354
- context ( 'serverSelectionTimeoutMS honored if timeoutMS is not set' , ( ) => {
358
+ it ( 'serverSelectionTimeoutMS honored if timeoutMS is not set' , async ( ) => {
355
359
/**
356
360
* 1. Create a MongoClient (referred to as `client`) with URI `mongodb://invalid/?serverSelectionTimeoutMS=10`.
357
361
* 1. Using `client`, execute the command `{ ping: 1 }` against the `admin` database.
358
362
* - Expect this to fail with a server selection timeout error after no more than 15ms.
359
363
*/
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 ) ;
360
380
} ) ;
361
381
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 ( ) ;
372
399
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 ( ) ;
383
421
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 ( ) => {
385
427
/**
386
428
* 1. Create a MongoClient (referred to as `client`) with URI `mongodb://invalid/?timeoutMS=0&serverSelectionTimeoutMS=10`.
387
429
* 1. Using `client`, run the command `{ ping: 1 }` against the `admin` database.
388
430
* - Expect this to fail with a server selection timeout error after no more than 15ms.
389
431
*/
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 ) ;
390
446
} ) ;
391
447
392
448
context (
@@ -440,7 +496,7 @@ describe.skip('CSOT spec prose tests', () => {
440
496
) ;
441
497
} ) ;
442
498
443
- context ( '9. endSession' , ( ) => {
499
+ context . skip ( '9. endSession' , ( ) => {
444
500
/**
445
501
* This test MUST only be run against replica sets and sharded clusters with server version 4.4 or higher. It MUST be
446
502
* 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', () => {
472
528
*/
473
529
} ) ;
474
530
475
- context ( '10. Convenient Transactions' , ( ) => {
531
+ context . skip ( '10. Convenient Transactions' , ( ) => {
476
532
/** Tests in this section MUST only run against replica sets and sharded clusters with server versions 4.4 or higher. */
477
533
478
534
context ( 'timeoutMS is refreshed for abortTransaction if the callback fails' , ( ) => {
0 commit comments