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
|
load("jstests/libs/parallelTester.js");
function configureReplSetFailpoint(st, kDbName, failpoint, modeValue) {
st.rs0.nodes.forEach(function(node) {
assert.commandWorked(node.getDB("admin").runCommand({
configureFailPoint: failpoint,
mode: modeValue,
data: {
shouldCheckForInterrupt: true,
nss: kDbName + ".test",
},
}));
});
}
function launchFinds(mongos, threads, {times, readPref, shouldFail}) {
jsTestLog("Starting " + times + " connections");
for (var i = 0; i < times; i++) {
var thread = new Thread(function(connStr, readPref, dbName, shouldFail) {
var client = new Mongo(connStr);
const ret = client.getDB(dbName).runCommand(
{find: "test", limit: 1, "$readPreference": {mode: readPref}});
if (shouldFail) {
assert.commandFailed(ret);
} else {
assert.commandWorked(ret);
}
}, mongos.host, readPref, 'test', shouldFail);
thread.start();
threads.push(thread);
}
}
function assertHasConnPoolStats(mongos, allHosts, args, checkNum) {
checkNum++;
jsTestLog("Check #" + checkNum + ": " + tojson(args));
var {ready = 0, pending = 0, active = 0, hosts = allHosts, isAbsent, checkStatsFunc} = args;
checkStatsFunc = checkStatsFunc ? checkStatsFunc : function(stats) {
return stats.available == ready && stats.refreshing == pending && stats.inUse == active;
};
function checkStats(res, host) {
var stats = res.hosts[host];
if (!stats) {
jsTestLog("Connection stats for " + host + " are absent");
return isAbsent;
}
jsTestLog("Connection stats for " + host + ": " + tojson(stats));
return checkStatsFunc(stats);
}
function checkAllStats() {
var res = mongos.adminCommand({connPoolStats: 1});
return hosts.map(host => checkStats(res, host)).every(x => x);
}
assert.soon(checkAllStats, "Check #" + checkNum + " failed", 10000);
jsTestLog("Check #" + checkNum + " successful");
return checkNum;
}
|