2
2
3
3
import { expect } from 'chai' ;
4
4
5
- import { MongoClient , MongoServerSelectionError , now } from '../../mongodb' ;
5
+ import {
6
+ MongoClient ,
7
+ MongoOperationTimeoutError ,
8
+ MongoServerSelectionError ,
9
+ now
10
+ } from '../../mongodb' ;
6
11
7
12
// TODO(NODE-5824): Implement CSOT prose tests
8
- describe ( 'CSOT spec prose tests' , ( ) => {
13
+ describe ( 'CSOT spec prose tests' , function ( ) {
14
+ let internalClient : MongoClient ;
15
+ let client : MongoClient ;
16
+
17
+ beforeEach ( async function ( ) {
18
+ internalClient = this . configuration . newClient ( ) ;
19
+ } ) ;
20
+
21
+ afterEach ( async function ( ) {
22
+ await internalClient ?. close ( ) ;
23
+ await client ?. close ( ) ;
24
+ } ) ;
25
+
9
26
context . skip ( '1. Multi-batch writes' , ( ) => {
10
27
/**
11
28
* This test MUST only run against standalones on server versions 4.4 and higher.
@@ -355,37 +372,32 @@ describe('CSOT spec prose tests', () => {
355
372
} ) ;
356
373
357
374
context ( '8. Server Selection' , ( ) => {
358
- it ( 'serverSelectionTimeoutMS honored if timeoutMS is not set' , async ( ) => {
375
+ it ( 'serverSelectionTimeoutMS honored if timeoutMS is not set' , async function ( ) {
359
376
/**
360
377
* 1. Create a MongoClient (referred to as `client`) with URI `mongodb://invalid/?serverSelectionTimeoutMS=10`.
361
378
* 1. Using `client`, execute the command `{ ping: 1 }` against the `admin` database.
362
379
* - Expect this to fail with a server selection timeout error after no more than 15ms.
363
380
*/
364
- const client = new MongoClient ( 'mongodb://invalid/?serverSelectionTimeoutMS=10' ) ;
365
- let duration : number ;
381
+ client = new MongoClient ( 'mongodb://invalid/?serverSelectionTimeoutMS=10' ) ;
366
382
const admin = client . db ( 'test' ) . admin ( ) ;
367
383
const start = performance . now ( ) ;
368
- const maybeError = await admin
369
- . ping ( )
370
- . then (
371
- ( ) => null ,
372
- e => e
373
- )
374
- . finally ( ( ) => {
375
- duration = performance . now ( ) - start ;
376
- } ) ;
384
+ const maybeError = await admin . ping ( ) . then (
385
+ ( ) => null ,
386
+ e => e
387
+ ) ;
388
+ const end = performance . now ( ) ;
377
389
378
390
expect ( maybeError ) . to . be . instanceof ( MongoServerSelectionError ) ;
379
- expect ( duration ) . to . be . lte ( 15 ) ;
391
+ expect ( end - start ) . to . be . lte ( 15 ) ;
380
392
} ) ;
381
393
382
- it ( "timeoutMS honored for server selection if it's lower than serverSelectionTimeoutMS" , async ( ) => {
394
+ it ( "timeoutMS honored for server selection if it's lower than serverSelectionTimeoutMS" , async function ( ) {
383
395
/**
384
396
* 1. Create a MongoClient (referred to as `client`) with URI `mongodb://invalid/?timeoutMS=10&serverSelectionTimeoutMS=20`.
385
397
* 1. Using `client`, run the command `{ ping: 1 }` against the `admin` database.
386
398
* - Expect this to fail with a server selection timeout error after no more than 15ms.
387
399
*/
388
- const client = new MongoClient ( 'mongodb://invalid/?timeoutMS=10&serverSelectionTimeoutMS=20' ) ;
400
+ client = new MongoClient ( 'mongodb://invalid/?timeoutMS=10&serverSelectionTimeoutMS=20' ) ;
389
401
const start = now ( ) ;
390
402
const maybeError = await client
391
403
. db ( 'test' )
@@ -401,13 +413,13 @@ describe('CSOT spec prose tests', () => {
401
413
expect ( end - start ) . to . be . lte ( 15 ) ;
402
414
} ) ;
403
415
404
- it ( "serverSelectionTimeoutMS honored for server selection if it's lower than timeoutMS" , async ( ) => {
416
+ it ( "serverSelectionTimeoutMS honored for server selection if it's lower than timeoutMS" , async function ( ) {
405
417
/**
406
418
* 1. Create a MongoClient (referred to as `client`) with URI `mongodb://invalid/?timeoutMS=20&serverSelectionTimeoutMS=10`.
407
419
* 1. Using `client`, run the command `{ ping: 1 }` against the `admin` database.
408
420
* - Expect this to fail with a server selection timeout error after no more than 15ms.
409
421
*/
410
- const client = new MongoClient ( 'mongodb://invalid/?timeoutMS=20&serverSelectionTimeoutMS=10' ) ;
422
+ client = new MongoClient ( 'mongodb://invalid/?timeoutMS=20&serverSelectionTimeoutMS=10' ) ;
411
423
const start = now ( ) ;
412
424
const maybeError = await client
413
425
. db ( 'test' )
@@ -423,13 +435,13 @@ describe('CSOT spec prose tests', () => {
423
435
expect ( end - start ) . to . be . lte ( 15 ) ;
424
436
} ) ;
425
437
426
- it ( 'serverSelectionTimeoutMS honored for server selection if timeoutMS=0' , async ( ) => {
438
+ it ( 'serverSelectionTimeoutMS honored for server selection if timeoutMS=0' , async function ( ) {
427
439
/**
428
440
* 1. Create a MongoClient (referred to as `client`) with URI `mongodb://invalid/?timeoutMS=0&serverSelectionTimeoutMS=10`.
429
441
* 1. Using `client`, run the command `{ ping: 1 }` against the `admin` database.
430
442
* - Expect this to fail with a server selection timeout error after no more than 15ms.
431
443
*/
432
- const client = new MongoClient ( 'mongodb://invalid/?timeoutMS=0&serverSelectionTimeoutMS=10' ) ;
444
+ client = new MongoClient ( 'mongodb://invalid/?timeoutMS=0&serverSelectionTimeoutMS=10' ) ;
433
445
const start = now ( ) ;
434
446
const maybeError = await client
435
447
. db ( 'test' )
@@ -445,55 +457,78 @@ describe('CSOT spec prose tests', () => {
445
457
expect ( end - start ) . to . be . lte ( 15 ) ;
446
458
} ) ;
447
459
448
- context (
449
- "timeoutMS honored for connection handshake commands if it's lower than serverSelectionTimeoutMS" ,
450
- ( ) => {
451
- /**
452
- * This test MUST only be run if the server version is 4.4 or higher and the URI has authentication fields (i.e. a
453
- * username and password).
454
- * 1. Using `internalClient`, set the following fail point:
455
- * ```js
456
- * {
457
- * configureFailPoint: failCommand,
458
- * mode: { times: 1 },
459
- * data: {
460
- * failCommands: ["saslContinue"],
461
- * blockConnection: true,
462
- * blockTimeMS: 15
463
- * }
464
- * }
465
- * ```
466
- * 1. Create a new MongoClient (referred to as `client`) with `timeoutMS=10` and `serverSelectionTimeoutMS=20`.
467
- * 1. Using `client`, insert the document `{ x: 1 }` into collection `db.coll`.
468
- * - Expect this to fail with a timeout error after no more than 15ms.
469
- */
470
- }
471
- ) ;
472
-
473
- context (
474
- "serverSelectionTimeoutMS honored for connection handshake commands if it's lower than timeoutMS" ,
475
- ( ) => {
476
- /**
477
- * This test MUST only be run if the server version is 4.4 or higher and the URI has authentication fields (i.e. a
478
- * username and password).
479
- * 1. Using `internalClient`, set the following fail point:
480
- * ```js
481
- * {
482
- * configureFailPoint: failCommand,
483
- * mode: { times: 1 },
484
- * data: {
485
- * failCommands: ["saslContinue"],
486
- * blockConnection: true,
487
- * blockTimeMS: 15
488
- * }
489
- * }
490
- * ```
491
- * 1. Create a new MongoClient (referred to as `client`) with `timeoutMS=20` and `serverSelectionTimeoutMS=10`.
492
- * 1. Using `client`, insert the document `{ x: 1 }` into collection `db.coll`.
493
- * - Expect this to fail with a timeout error after no more than 15ms.
494
- */
495
- }
496
- ) ;
460
+ it ( "timeoutMS honored for connection handshake commands if it's lower than serverSelectionTimeoutMS" , function ( ) {
461
+ /**
462
+ * This test MUST only be run if the server version is 4.4 or higher and the URI has authentication fields (i.e. a
463
+ * username and password).
464
+ * 1. Using `internalClient`, set the following fail point:
465
+ * ```js
466
+ * {
467
+ * configureFailPoint: failCommand,
468
+ * mode: { times: 1 },
469
+ * data: {
470
+ * failCommands: ["saslContinue"],
471
+ * blockConnection: true,
472
+ * blockTimeMS: 15
473
+ * }
474
+ * }
475
+ * ```
476
+ * 1. Create a new MongoClient (referred to as `client`) with `timeoutMS=10` and `serverSelectionTimeoutMS=20`.
477
+ * 1. Using `client`, insert the document `{ x: 1 }` into collection `db.coll`.
478
+ * - Expect this to fail with a timeout error after no more than 15ms.
479
+ */
480
+ } ) ;
481
+
482
+ it ( "serverSelectionTimeoutMS honored for connection handshake commands if it's lower than timeoutMS" , async function ( ) {
483
+ /**
484
+ * This test MUST only be run if the server version is 4.4 or higher and the URI has authentication fields (i.e. a
485
+ * username and password).
486
+ * 1. Using `internalClient`, set the following fail point:
487
+ * ```js
488
+ * {
489
+ * configureFailPoint: failCommand,
490
+ * mode: { times: 1 },
491
+ * data: {
492
+ * failCommands: ["saslContinue"],
493
+ * blockConnection: true,
494
+ * blockTimeMS: 15
495
+ * }
496
+ * }
497
+ * ```
498
+ * 1. Create a new MongoClient (referred to as `client`) with `timeoutMS=20` and `serverSelectionTimeoutMS=10`.
499
+ * 1. Using `client`, insert the document `{ x: 1 }` into collection `db.coll`.
500
+ * - Expect this to fail with a timeout error after no more than 15ms.
501
+ */
502
+ await internalClient
503
+ . db ( 'db' )
504
+ . admin ( )
505
+ . command ( {
506
+ configureFailPoint : 'failCommand' ,
507
+ mode : { times : 1 } ,
508
+ data : {
509
+ failCommands : [ 'saslContinue' ] ,
510
+ blockConnection : true ,
511
+ blockTimeMS : 15
512
+ }
513
+ } ) ;
514
+
515
+ client = this . configuration . newClient ( {
516
+ serverSelectionTimeoutMS : 10 ,
517
+ timeoutMS : 20
518
+ } ) ;
519
+ const start = now ( ) ;
520
+ const maybeError = await client
521
+ . db ( 'db' )
522
+ . collection ( 'coll' )
523
+ . insertOne ( { x : 1 } )
524
+ . then (
525
+ ( ) => null ,
526
+ e => e
527
+ ) ;
528
+ const end = now ( ) ;
529
+ expect ( end - start ) . to . be . lte ( 15 ) ;
530
+ expect ( maybeError ) . to . be . instanceof ( MongoOperationTimeoutError ) ;
531
+ } ) ;
497
532
} ) ;
498
533
499
534
context . skip ( '9. endSession' , ( ) => {
0 commit comments