-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
retryable_writes.spec.prose.test.ts
56 lines (48 loc) · 1.99 KB
/
retryable_writes.spec.prose.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { expect } from 'chai';
import { MongoError, MongoServerError } from '../../../src';
describe('Retryable Writes Spec Prose', () => {
/**
* 1 Test that retryable writes raise an exception when using the MMAPv1 storage engine.
* For this test, execute a write operation, such as insertOne, which should generate an exception and the error code is 20.
* Assert that the error message is the replacement error message:
*
* ```
* This MongoDB deployment does not support retryable writes. Please add
* retryWrites=false to your connection string.
* ```
* 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.
*/
let client;
beforeEach(async function () {
client = this.configuration.newClient();
await client.connect();
});
afterEach(async () => {
await client?.close();
});
it.skip('retryable writes raise an exception when using the MMAPv1 storage engine', async () => {
const failPoint = await client.db('admin').command({
configureFailPoint: 'failCommand',
mode: { times: 1 },
data: {
failCommands: ['insert'],
errorCode: 20, // MMAP Error code,
closeConnection: false
}
});
expect(failPoint).to.have.property('ok', 1);
const error = await client
.db('test')
.collection('test')
.insertOne({ a: 1 })
.catch(error => error);
expect(error).to.exist;
expect(error).to.be.instanceOf(MongoServerError);
expect(error).to.have.property('originalError').that.instanceOf(MongoError);
expect(error.originalError).to.have.property('code', 20);
expect(error).to.have.property(
'message',
'This MongoDB deployment does not support retryable writes. Please add retryWrites=false to your connection string.'
);
}).skipReason = 'TODO, might need to limit server versions? 3.6 fails, 4.x has different shape';
});