Skip to content

Commit 7632335

Browse files
committed
continue prose test implementation
1 parent bb8b4b0 commit 7632335

File tree

1 file changed

+105
-70
lines changed

1 file changed

+105
-70
lines changed

test/integration/client-side-operations-timeout/client_side_operations_timeout.prose.test.ts

Lines changed: 105 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,27 @@
22

33
import { expect } from 'chai';
44

5-
import { MongoClient, MongoServerSelectionError, now } from '../../mongodb';
5+
import {
6+
MongoClient,
7+
MongoOperationTimeoutError,
8+
MongoServerSelectionError,
9+
now
10+
} from '../../mongodb';
611

712
// 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+
926
context.skip('1. Multi-batch writes', () => {
1027
/**
1128
* This test MUST only run against standalones on server versions 4.4 and higher.
@@ -355,37 +372,32 @@ describe('CSOT spec prose tests', () => {
355372
});
356373

357374
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 () {
359376
/**
360377
* 1. Create a MongoClient (referred to as `client`) with URI `mongodb://invalid/?serverSelectionTimeoutMS=10`.
361378
* 1. Using `client`, execute the command `{ ping: 1 }` against the `admin` database.
362379
* - Expect this to fail with a server selection timeout error after no more than 15ms.
363380
*/
364-
const client = new MongoClient('mongodb://invalid/?serverSelectionTimeoutMS=10');
365-
let duration: number;
381+
client = new MongoClient('mongodb://invalid/?serverSelectionTimeoutMS=10');
366382
const admin = client.db('test').admin();
367383
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();
377389

378390
expect(maybeError).to.be.instanceof(MongoServerSelectionError);
379-
expect(duration).to.be.lte(15);
391+
expect(end - start).to.be.lte(15);
380392
});
381393

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 () {
383395
/**
384396
* 1. Create a MongoClient (referred to as `client`) with URI `mongodb://invalid/?timeoutMS=10&serverSelectionTimeoutMS=20`.
385397
* 1. Using `client`, run the command `{ ping: 1 }` against the `admin` database.
386398
* - Expect this to fail with a server selection timeout error after no more than 15ms.
387399
*/
388-
const client = new MongoClient('mongodb://invalid/?timeoutMS=10&serverSelectionTimeoutMS=20');
400+
client = new MongoClient('mongodb://invalid/?timeoutMS=10&serverSelectionTimeoutMS=20');
389401
const start = now();
390402
const maybeError = await client
391403
.db('test')
@@ -401,13 +413,13 @@ describe('CSOT spec prose tests', () => {
401413
expect(end - start).to.be.lte(15);
402414
});
403415

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 () {
405417
/**
406418
* 1. Create a MongoClient (referred to as `client`) with URI `mongodb://invalid/?timeoutMS=20&serverSelectionTimeoutMS=10`.
407419
* 1. Using `client`, run the command `{ ping: 1 }` against the `admin` database.
408420
* - Expect this to fail with a server selection timeout error after no more than 15ms.
409421
*/
410-
const client = new MongoClient('mongodb://invalid/?timeoutMS=20&serverSelectionTimeoutMS=10');
422+
client = new MongoClient('mongodb://invalid/?timeoutMS=20&serverSelectionTimeoutMS=10');
411423
const start = now();
412424
const maybeError = await client
413425
.db('test')
@@ -423,13 +435,13 @@ describe('CSOT spec prose tests', () => {
423435
expect(end - start).to.be.lte(15);
424436
});
425437

426-
it('serverSelectionTimeoutMS honored for server selection if timeoutMS=0', async () => {
438+
it('serverSelectionTimeoutMS honored for server selection if timeoutMS=0', async function () {
427439
/**
428440
* 1. Create a MongoClient (referred to as `client`) with URI `mongodb://invalid/?timeoutMS=0&serverSelectionTimeoutMS=10`.
429441
* 1. Using `client`, run the command `{ ping: 1 }` against the `admin` database.
430442
* - Expect this to fail with a server selection timeout error after no more than 15ms.
431443
*/
432-
const client = new MongoClient('mongodb://invalid/?timeoutMS=0&serverSelectionTimeoutMS=10');
444+
client = new MongoClient('mongodb://invalid/?timeoutMS=0&serverSelectionTimeoutMS=10');
433445
const start = now();
434446
const maybeError = await client
435447
.db('test')
@@ -445,55 +457,78 @@ describe('CSOT spec prose tests', () => {
445457
expect(end - start).to.be.lte(15);
446458
});
447459

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+
});
497532
});
498533

499534
context.skip('9. endSession', () => {

0 commit comments

Comments
 (0)