diff options
author | Yoonsoo Kim <yoonsoo.kim@mongodb.com> | 2021-06-22 23:41:04 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-06-24 22:25:16 +0000 |
commit | b8b5d3de4df8e0f82491b5d5ccbc4b635f61aecf (patch) | |
tree | e559ebeac8d002e506744f22e7628f6cbdce4e61 /jstests | |
parent | 2b0329d1fbcf80c7666848895ca85f5f6af6f4c2 (diff) | |
download | mongo-b8b5d3de4df8e0f82491b5d5ccbc4b635f61aecf.tar.gz |
SERVER-57897 Add readPrefMode option to benchRun find/findOne ops
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/noPassthrough/benchrun_read_pref_mode.js | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/jstests/noPassthrough/benchrun_read_pref_mode.js b/jstests/noPassthrough/benchrun_read_pref_mode.js new file mode 100644 index 00000000000..04873352170 --- /dev/null +++ b/jstests/noPassthrough/benchrun_read_pref_mode.js @@ -0,0 +1,99 @@ +/** + * Verifies that readPrefMode param works for find/fineOne/query ops in benchRun(). + * + * @tags: [requires_replication] + */ + +(function() { +"use strict"; + +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(); +})(); |