mirror of
https://github.com/mongodb/mongo.git
synced 2024-11-27 15:06:34 +01:00
771dabd098
GitOrigin-RevId: 744aa110a53786b23c62ff53f87a1418b5991e8d
97 lines
2.4 KiB
JavaScript
97 lines
2.4 KiB
JavaScript
/**
|
|
* Verifies that readPrefMode param works for find/fineOne/query ops in benchRun().
|
|
*
|
|
* @tags: [requires_replication]
|
|
*/
|
|
|
|
import {ReplSetTest} from "jstests/libs/replsettest.js";
|
|
|
|
const rs = new ReplSetTest({nodes: 2});
|
|
rs.startSet();
|
|
rs.initiate();
|
|
|
|
const primary = rs.getPrimary();
|
|
const secondary = rs.getSecondary();
|
|
const collName = primary.getDB(jsTestName()).getCollection("coll").getFullName();
|
|
|
|
const verifyNoError = res => {
|
|
assert.eq(res.errCount, 0);
|
|
assert.gt(res.totalOps, 0);
|
|
};
|
|
|
|
const benchArgArray = [
|
|
{
|
|
ops: [{op: "find", readCmd: true, query: {}, ns: collName, readPrefMode: "primary"}],
|
|
parallel: 1,
|
|
host: primary.host
|
|
},
|
|
{
|
|
ops: [{
|
|
op: "findOne",
|
|
readCmd: true,
|
|
query: {},
|
|
ns: collName,
|
|
readPrefMode: "primaryPreferred"
|
|
}],
|
|
parallel: 1,
|
|
host: primary.host
|
|
},
|
|
{
|
|
ops: [{op: "find", readCmd: true, query: {}, ns: collName, readPrefMode: "secondary"}],
|
|
parallel: 1,
|
|
host: secondary.host
|
|
},
|
|
{
|
|
ops: [{
|
|
op: "findOne",
|
|
readCmd: true,
|
|
query: {},
|
|
ns: collName,
|
|
readPrefMode: "secondaryPreferred"
|
|
}],
|
|
parallel: 1,
|
|
host: secondary.host
|
|
},
|
|
{
|
|
ops: [{op: "query", readCmd: true, query: {}, ns: collName, readPrefMode: "nearest"}],
|
|
parallel: 1,
|
|
host: secondary.host
|
|
},
|
|
];
|
|
|
|
benchArgArray.forEach(benchArg => verifyNoError(benchRun(benchArg)));
|
|
|
|
const invalidArgAndError = [
|
|
{
|
|
benchArg: {
|
|
ops: [{op: "find", readCmd: true, query: {}, ns: collName, readPrefMode: 1}],
|
|
parallel: 1,
|
|
host: primary.host
|
|
},
|
|
error: ErrorCodes.BadValue
|
|
},
|
|
{
|
|
benchArg: {
|
|
ops:
|
|
[{op: "find", readCmd: true, query: {}, ns: collName, readPrefMode: "invalidPref"}],
|
|
parallel: 1,
|
|
host: primary.host
|
|
},
|
|
error: ErrorCodes.BadValue
|
|
},
|
|
{
|
|
benchArg: {
|
|
ops: [
|
|
{op: "insert", writeCmd: true, doc: {a: 1}, ns: collName, readPrefMode: "primary"}
|
|
],
|
|
parallel: 1,
|
|
host: primary.host
|
|
},
|
|
error: ErrorCodes.InvalidOptions
|
|
},
|
|
];
|
|
|
|
invalidArgAndError.forEach(
|
|
argAndError => assert.throwsWithCode(() => benchRun(argAndError.benchArg), argAndError.error));
|
|
|
|
rs.stopSet(); |