summaryrefslogtreecommitdiff
path: root/jstests/core/benchrun_cmd_param_error.js
diff options
context:
space:
mode:
authorYoonsoo Kim <yoonsoo.kim@mongodb.com>2021-06-16 18:10:38 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-06-17 16:10:00 +0000
commitd8484ccdb02cc9c13784385413722b5d00268081 (patch)
treeda7d3e43c31e68fdfcaf5c541179f02655b711a4 /jstests/core/benchrun_cmd_param_error.js
parent970f9b4ef4d16954a4d1fddebce6f104dd8e7123 (diff)
downloadmongo-d8484ccdb02cc9c13784385413722b5d00268081.tar.gz
SERVER-57514 Have shell's benchRun() use OP_MSG protocol and not use getLastError
Diffstat (limited to 'jstests/core/benchrun_cmd_param_error.js')
-rw-r--r--jstests/core/benchrun_cmd_param_error.js114
1 files changed, 114 insertions, 0 deletions
diff --git a/jstests/core/benchrun_cmd_param_error.js b/jstests/core/benchrun_cmd_param_error.js
new file mode 100644
index 00000000000..9055e9e2cb3
--- /dev/null
+++ b/jstests/core/benchrun_cmd_param_error.js
@@ -0,0 +1,114 @@
+/**
+ * Verifies that benchRun() fails in the following cases.
+ *
+ * - No readCmd param or readCmd: false is specified for read ops
+ * - No writeCmd param or writeCmd: false is specified for write ops
+ * - Exhaust query is requested
+ */
+(function() {
+"use strict";
+
+const testDB = db.getSiblingDB(jsTestName());
+testDB.dropDatabase();
+const coll = testDB.coll;
+
+// Composes the common benchRun() args.
+const benchArgs = {
+ ops: [],
+ parallel: 1,
+ seconds: 1,
+ host: db.getMongo().host
+};
+if (jsTest.options().auth) {
+ benchArgs["db"] = "admin";
+ benchArgs["username"] = jsTest.options().authUser;
+ benchArgs["password"] = jsTest.options().authPassword;
+}
+
+const readCmdParamError = 5751400;
+const writeCmdParamError = 5751401;
+const exhaustOptionError = 5751402;
+
+const opsAndErrors = [
+ // No writeCmd param for insert op will get an error.
+ {op: {ns: coll.getFullName(), op: "insert", doc: [{_id: 0, a: 1}]}, error: writeCmdParamError},
+ // The writeCmd: false for update op will get an error.
+ {
+ op: {ns: coll.getFullName(), op: "insert", doc: [{_id: 0, a: 1}], writeCmd: false},
+ error: writeCmdParamError
+ },
+ // No writeCmd param for update op will get an error.
+ {
+ op: {
+ ns: coll.getFullName(),
+ op: "update",
+ query: {_id: 0},
+ update: {$inc: {a: 1}},
+ },
+ error: writeCmdParamError
+ },
+ // The writeCmd: false for update op will get an error.
+ {
+ op: {
+ ns: coll.getFullName(),
+ op: "update",
+ query: {_id: 0},
+ update: {$inc: {a: 1}},
+ writeCmd: false
+ },
+ error: writeCmdParamError
+ },
+ // No writeCmd param for delete op will get an error.
+ {
+ op: {
+ ns: coll.getFullName(),
+ op: "delete",
+ query: {_id: 0},
+ },
+ error: writeCmdParamError
+ },
+ // The writeCmd: false for delete op will get an error.
+ {
+ op: {ns: coll.getFullName(), op: "delete", query: {_id: 0}, writeCmd: false},
+ error: writeCmdParamError
+ },
+ // No readCmd param for findOne op will get an error.
+ {op: {ns: coll.getFullName(), op: "findOne", query: {}}, error: readCmdParamError},
+ // The readCmd: false for findOne op will get an error.
+ {
+ op: {ns: coll.getFullName(), op: "findOne", query: {}, readCmd: false},
+ error: readCmdParamError
+ },
+ // No readCmd param for find op will get an error.
+ {op: {ns: coll.getFullName(), op: "find", query: {}}, error: readCmdParamError},
+ // The readCmd: false for find op will get an error.
+ {op: {ns: coll.getFullName(), op: "find", query: {}, readCmd: false}, error: readCmdParamError},
+ // Exhaust query for read op is not supported for benchRun().
+ {
+ op: {
+ ns: coll.getFullName(),
+ op: "find",
+ query: {},
+ options: DBQuery.Option.exhaust,
+ readCmd: true
+ },
+ error: exhaustOptionError
+ },
+ // Exhaust query for command op is not supported for benchRun().
+ {
+ op: {
+ ns: testDB.getName(),
+ op: "command",
+ command: {"find": coll.getName()},
+ options: DBQuery.Option.exhaust
+ },
+ error: exhaustOptionError
+ },
+];
+
+opsAndErrors.forEach(opAndError => {
+ benchArgs.ops = [opAndError.op];
+
+ assert.throwsWithCode(() => benchRun(benchArgs), opAndError.error);
+});
+})();