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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
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);
});
})();
|