-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathserver_selection_timeout_cleanup.test.ts
More file actions
87 lines (79 loc) · 2.84 KB
/
server_selection_timeout_cleanup.test.ts
File metadata and controls
87 lines (79 loc) · 2.84 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { expect } from 'chai';
import * as process from 'process';
import { setTimeout } from 'timers/promises';
import { type Collection, type MongoClient } from '../../mongodb';
describe.only('server selection timeout cleanup', function () {
let client: MongoClient;
let collection: Collection;
let utilClients: MongoClient[];
describe(
'timeout cleanup on retries',
{ requires: { topology: 'sharded', mongodb: '>=4.4' } },
function () {
beforeEach(async function () {
client = this.configuration.newClient(
this.configuration.url({ useMultipleMongoses: true }),
{ serverSelectionTimeoutMS: 500, retryWrites: true }
);
await client.connect();
collection = client.db('server_selection').collection('timeout_cleanup');
utilClients = [];
// we need to configure failpoint for every mongos as we don't know where the session will be pinned to
const seeds = client.topology.s.seedlist.map(address => address.toString());
for (const seed of seeds) {
const c = this.configuration.newClient(`mongodb://${seed}`, {
directConnection: true
});
await c.connect();
await c.db('admin').command({
configureFailPoint: 'failCommand',
mode: { times: 1 },
data: {
failCommands: ['insert'],
errorCode: 6,
errorLabels: ['RetryableWriteError'],
closeConnection: false
}
});
utilClients.push(c);
}
});
afterEach(async function () {
for (const c of utilClients) {
await c.db('admin').command({
configureFailPoint: 'failCommand',
mode: 'off',
data: {
failCommands: ['insert'],
errorCode: 6,
errorLabels: ['RetryableWriteError'],
closeConnection: false
}
});
await c.close();
}
await client.close();
});
it('does not leak timeout when retrying inside a sharded transaction', async function () {
const unhandlerRejections = [];
const handler = reason => unhandlerRejections.push(reason);
process.on('unhandledRejection', handler);
try {
const session = client.startSession();
try {
session.startTransaction();
await collection.find({}, { session }).toArray();
await collection.insertOne({ foo: 'bar' }, { session });
await session.commitTransaction();
} finally {
await session.endSession();
}
await setTimeout(1000);
expect(unhandlerRejections.length).to.have.lengthOf(0);
} finally {
process.removeListener('unhandledRejection', handler);
}
});
}
);
});