Skip to content

Commit 1a1895a

Browse files
committed
test(NODE-3688): reorganise tests
1 parent fc5617f commit 1a1895a

6 files changed

+294
-292
lines changed

test/integration/retryable-reads/retryable_reads.prose.spec.test.ts

-80
This file was deleted.

test/integration/retryable-reads/retryable_reads.spec.test.js

+88-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1-
'use strict';
2-
1+
const { expect } = require('chai');
32
const path = require('path');
3+
const semver = require('semver');
44
const { TestRunnerContext, generateTopologyTests } = require('../../tools/spec-runner');
55
const { loadSpecTests } = require('../../spec');
66
const { runUnifiedSuite } = require('../../tools/unified-spec-runner/runner');
7+
const { TopologyType } = require('../../../src');
8+
9+
const VALID_TOPOLOGIES = [
10+
TopologyType.ReplicaSetWithPrimary,
11+
TopologyType.Sharded,
12+
TopologyType.LoadBalanced
13+
];
714

815
describe('Retryable Reads (legacy)', function () {
916
const testContext = new TestRunnerContext();
@@ -34,6 +41,83 @@ describe('Retryable Reads (legacy)', function () {
3441
// These tests are skipped because the driver 1) executes a ping when connecting to
3542
// an authenticated server and 2) command monitoring is at the connection level so
3643
// when the handshake fails no command started event is emitted.
37-
describe.skip('Retryable Reads (unified)', function () {
38-
runUnifiedSuite(loadSpecTests(path.join('retryable-reads', 'unified')));
44+
const SKIP = [
45+
'find succeeds after retryable handshake network error',
46+
'find succeeds after retryable handshake network error (ShutdownInProgress)'
47+
];
48+
49+
describe('Retryable Reads (unified)', function () {
50+
runUnifiedSuite(loadSpecTests(path.join('retryable-reads', 'unified')), SKIP);
51+
});
52+
53+
describe('Retryable Reads', function () {
54+
const dbName = 'retryable-handshake-tests';
55+
const collName = 'coll';
56+
const docs = [
57+
{ _id: 1, x: 11 },
58+
{ _id: 2, x: 22 },
59+
{ _id: 3, x: 33 }
60+
];
61+
let client;
62+
let db;
63+
let coll;
64+
65+
beforeEach(function () {
66+
if (
67+
semver.lt(this.configuration.buildInfo.version, '4.2.0') ||
68+
!VALID_TOPOLOGIES.includes(this.configuration.topologyType)
69+
) {
70+
this.currentTest.skipReason =
71+
'Retryable reads tests require MongoDB 4.2 and higher and no standalone';
72+
this.skip();
73+
}
74+
client = this.configuration.newClient({});
75+
db = client.db(dbName);
76+
coll = db.collection(collName);
77+
});
78+
79+
afterEach(async function () {
80+
if (db) {
81+
await db.admin().command({
82+
configureFailPoint: 'failCommand',
83+
mode: 'off'
84+
});
85+
await coll.drop();
86+
await client.close();
87+
}
88+
});
89+
90+
context('when the handshake fails with a network error', function () {
91+
it('retries the read', async function () {
92+
await client.connect();
93+
await coll.insertMany(docs);
94+
await db.admin().command({
95+
configureFailPoint: 'failCommand',
96+
mode: { times: 2 },
97+
data: {
98+
failCommands: ['saslContinue', 'ping'],
99+
closeConnection: true
100+
}
101+
});
102+
const documents = await coll.find().toArray();
103+
expect(documents).to.deep.equal(docs);
104+
});
105+
});
106+
107+
context('when the handshake fails with shutdown in progress', function () {
108+
it('retries the read', async function () {
109+
await client.connect();
110+
await coll.insertMany(docs);
111+
await db.admin().command({
112+
configureFailPoint: 'failCommand',
113+
mode: { times: 2 },
114+
data: {
115+
failCommands: ['saslContinue', 'ping'],
116+
errorCode: 91 // ShutdownInProgress
117+
}
118+
});
119+
const documents = await coll.find().toArray();
120+
expect(documents).to.deep.equal(docs);
121+
});
122+
});
39123
});
Original file line numberDiff line numberDiff line change
@@ -1,139 +1,64 @@
11
import { expect } from 'chai';
2-
import * as semver from 'semver';
32

43
import { MongoError, MongoServerError, TopologyType } from '../../../src';
54

6-
const VALID_TOPOLOGIES = [
7-
TopologyType.ReplicaSetWithPrimary,
8-
TopologyType.Sharded,
9-
TopologyType.LoadBalanced
10-
];
11-
125
describe('Retryable Writes Spec Prose', () => {
13-
context('when checking against mmapv1', () => {
14-
/**
15-
* 1 Test that retryable writes raise an exception when using the MMAPv1 storage engine.
16-
* For this test, execute a write operation, such as insertOne, which should generate an exception and the error code is 20.
17-
* Assert that the error message is the replacement error message:
18-
*
19-
* ```
20-
* This MongoDB deployment does not support retryable writes. Please add
21-
* retryWrites=false to your connection string.
22-
* ```
23-
* Note: Drivers that rely on serverStatus to determine the storage engine in use MAY skip this test for sharded clusters, since mongos does not report this information in its serverStatus response.
24-
*/
25-
let client;
26-
27-
beforeEach(async function () {
28-
if (
29-
this.configuration.buildInfo.versionArray[0] < 4 ||
30-
this.configuration.topologyType !== TopologyType.ReplicaSetWithPrimary
31-
) {
32-
this.currentTest.skipReason =
33-
'configureFailPoint only works on server versions greater than 4';
34-
this.skip();
35-
}
36-
client = this.configuration.newClient();
37-
await client.connect();
38-
});
39-
40-
afterEach(async () => {
41-
await client?.close();
42-
});
43-
44-
it('retryable writes raise an exception when using the MMAPv1 storage engine', async () => {
45-
const failPoint = await client.db('admin').command({
46-
configureFailPoint: 'failCommand',
47-
mode: { times: 1 },
48-
data: {
49-
failCommands: ['insert'],
50-
errorCode: 20, // MMAP Error code,
51-
closeConnection: false
52-
}
53-
});
6+
/**
7+
* 1 Test that retryable writes raise an exception when using the MMAPv1 storage engine.
8+
* For this test, execute a write operation, such as insertOne, which should generate an exception and the error code is 20.
9+
* Assert that the error message is the replacement error message:
10+
*
11+
* ```
12+
* This MongoDB deployment does not support retryable writes. Please add
13+
* retryWrites=false to your connection string.
14+
* ```
15+
* Note: Drivers that rely on serverStatus to determine the storage engine in use MAY skip this test for sharded clusters, since mongos does not report this information in its serverStatus response.
16+
*/
17+
let client;
5418

55-
expect(failPoint).to.have.property('ok', 1);
56-
57-
const error = await client
58-
.db('test')
59-
.collection('test')
60-
.insertOne({ a: 1 })
61-
.catch(error => error);
62-
63-
expect(error).to.exist;
64-
expect(error).that.is.instanceOf(MongoServerError);
65-
expect(error).to.have.property('originalError').that.instanceOf(MongoError);
66-
expect(error.originalError).to.have.property('code', 20);
67-
expect(error).to.have.property(
68-
'message',
69-
'This MongoDB deployment does not support retryable writes. Please add retryWrites=false to your connection string.'
70-
);
71-
});
19+
beforeEach(async function () {
20+
if (
21+
this.configuration.buildInfo.versionArray[0] < 4 ||
22+
this.configuration.topologyType !== TopologyType.ReplicaSetWithPrimary
23+
) {
24+
this.currentTest.skipReason =
25+
'configureFailPoint only works on server versions greater than 4';
26+
this.skip();
27+
}
28+
client = this.configuration.newClient();
29+
await client.connect();
7230
});
7331

74-
context('when errors occur in the handshake', function () {
75-
const dbName = 'retryable-handshake-tests';
76-
const collName = 'coll';
77-
const docs = [{ _id: 1, x: 11 }];
78-
let client;
79-
let db;
80-
let coll;
32+
afterEach(async () => {
33+
await client?.close();
34+
});
8135

82-
beforeEach(function () {
83-
if (
84-
semver.lt(this.configuration.buildInfo.version, '4.2.0') ||
85-
!VALID_TOPOLOGIES.includes(this.configuration.topologyType)
86-
) {
87-
this.currentTest.skipReason =
88-
'Retryable writes tests require MongoDB 4.2 and higher and no standalone';
89-
this.skip();
36+
it('retryable writes raise an exception when using the MMAPv1 storage engine', async () => {
37+
const failPoint = await client.db('admin').command({
38+
configureFailPoint: 'failCommand',
39+
mode: { times: 1 },
40+
data: {
41+
failCommands: ['insert'],
42+
errorCode: 20, // MMAP Error code,
43+
closeConnection: false
9044
}
91-
client = this.configuration.newClient({});
92-
db = client.db(dbName);
93-
coll = db.collection(collName);
9445
});
9546

96-
afterEach(async function () {
97-
await db?.admin().command({
98-
configureFailPoint: 'failCommand',
99-
mode: 'off'
100-
});
101-
await coll?.drop();
102-
await client?.close();
103-
});
47+
expect(failPoint).to.have.property('ok', 1);
10448

105-
context('when the handshake fails with a network error', function () {
106-
it('retries the write', async function () {
107-
await client.connect();
108-
await coll.insertMany(docs);
109-
await db.admin().command({
110-
configureFailPoint: 'failCommand',
111-
mode: { times: 2 },
112-
data: {
113-
failCommands: ['saslContinue', 'ping'],
114-
closeConnection: true
115-
}
116-
});
117-
const result = await coll.insertOne({ _id: 2, x: 22 });
118-
expect(result.insertedId).to.equal(2);
119-
});
120-
});
49+
const error = await client
50+
.db('test')
51+
.collection('test')
52+
.insertOne({ a: 1 })
53+
.catch(error => error);
12154

122-
context('when the handshake fails with shutdown in progress', function () {
123-
it('retries the write', async function () {
124-
await client.connect();
125-
await coll.insertMany(docs);
126-
await db.admin().command({
127-
configureFailPoint: 'failCommand',
128-
mode: { times: 2 },
129-
data: {
130-
failCommands: ['saslContinue', 'ping'],
131-
errorCode: 91 // ShutdownInProgress
132-
}
133-
});
134-
const result = await coll.insertOne({ _id: 2, x: 22 });
135-
expect(result.insertedId).to.equal(2);
136-
});
137-
});
55+
expect(error).to.exist;
56+
expect(error).that.is.instanceOf(MongoServerError);
57+
expect(error).to.have.property('originalError').that.instanceOf(MongoError);
58+
expect(error.originalError).to.have.property('code', 20);
59+
expect(error).to.have.property(
60+
'message',
61+
'This MongoDB deployment does not support retryable writes. Please add retryWrites=false to your connection string.'
62+
);
13863
});
13964
});

0 commit comments

Comments
 (0)