blob: bebc101a7f9d7447767e4f2b4392130e74546abc (
plain)
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
|
/**
* Ensures that the dropDatabase shell helper accepts a write concern as its first argument.
*
* @tags: [requires_replication]
*/
(function() {
"use strict";
function checkWriteConcern(testFn, checkFn) {
const mongoRunCommandOriginal = Mongo.prototype.runCommand;
const sentinel = {};
let cmdObjSeen = sentinel;
Mongo.prototype.runCommand = function runCommandSpy(dbName, cmdObj, options) {
cmdObjSeen = cmdObj;
return mongoRunCommandOriginal.apply(this, arguments);
};
try {
assert.doesNotThrow(testFn);
} finally {
Mongo.prototype.runCommand = mongoRunCommandOriginal;
}
if (cmdObjSeen == sentinel) {
throw new Error("Mongo.prototype.runCommand() was never called: " + testFn.toString());
}
checkFn(cmdObjSeen);
}
const rst = new ReplSetTest({nodes: 2});
rst.startSet();
rst.initiate();
const dbName = "dbDrop";
const collName = "coll";
const primaryDB = rst.getPrimary().getDB(dbName);
primaryDB.createCollection(collName);
checkWriteConcern(() => assert.commandWorked(primaryDB.dropDatabase({w: "majority"})), (cmdObj) => {
assert.eq(cmdObj.writeConcern, {w: "majority"});
});
primaryDB.createCollection(collName);
checkWriteConcern(() => assert.commandWorked(primaryDB.dropDatabase({w: 1})), (cmdObj) => {
assert.eq(cmdObj.writeConcern, {w: 1});
});
primaryDB.createCollection(collName);
checkWriteConcern(() => assert.commandFailedWithCode(primaryDB.dropDatabase({w: 45}),
ErrorCodes.UnsatisfiableWriteConcern),
(cmdObj) => {
assert.eq(cmdObj.writeConcern, {w: 45});
});
rst.stopSet();
})();
|