diff options
author | Gregory Wlodarek <gregory.wlodarek@mongodb.com> | 2019-05-07 13:05:00 -0400 |
---|---|---|
committer | Gregory Wlodarek <gregory.wlodarek@mongodb.com> | 2019-05-13 22:53:52 -0400 |
commit | cfd65015b39fe7b0db6aec288f69163bc5763812 (patch) | |
tree | 20b1be6bf4030c03d802ffee6666421db6020592 /jstests/replsets/drop_db.js | |
parent | 4309c3c77f28ccc27760e4781797b1d2afd8cb06 (diff) | |
download | mongo-cfd65015b39fe7b0db6aec288f69163bc5763812.tar.gz |
SERVER-40712 Ensure the dropDatabase() command accepts a write concern.
Diffstat (limited to 'jstests/replsets/drop_db.js')
-rw-r--r-- | jstests/replsets/drop_db.js | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/jstests/replsets/drop_db.js b/jstests/replsets/drop_db.js new file mode 100644 index 00000000000..69f34eba059 --- /dev/null +++ b/jstests/replsets/drop_db.js @@ -0,0 +1,60 @@ +/** + * 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: 100000}), + ErrorCodes.UnsatisfiableWriteConcern), + (cmdObj) => { + assert.eq(cmdObj.writeConcern, {w: 100000}); + }); + + rst.stopSet(); +})(); |