mirror of
https://github.com/mongodb/mongo.git
synced 2024-11-27 23:27:11 +01:00
19b971d34e
GitOrigin-RevId: 1127c4c7c118e291f5b3fcdb58959cdad9fd143c
53 lines
1.9 KiB
JavaScript
53 lines
1.9 KiB
JavaScript
import {Thread} from "jstests/libs/parallelTester.js";
|
|
|
|
export 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);
|
|
}
|
|
}
|
|
|
|
export function assertHasConnPoolStats(
|
|
mongos, allHosts, args, checkNum, connPoolStatsCmd = undefined) {
|
|
checkNum++;
|
|
jsTestLog("Check #" + checkNum + ": " + tojson(args));
|
|
let {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 + stats.leased) == active;
|
|
};
|
|
|
|
function checkStats(res, host) {
|
|
let 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() {
|
|
let cmdName = connPoolStatsCmd ? connPoolStatsCmd : "connPoolStats";
|
|
let res = mongos.adminCommand({[cmdName]: 1});
|
|
return hosts.map(host => checkStats(res, host)).every(x => x);
|
|
}
|
|
|
|
assert.soon(checkAllStats, "Check #" + checkNum + " failed", 10000);
|
|
jsTestLog("Check #" + checkNum + " successful");
|
|
return checkNum;
|
|
}
|