summaryrefslogtreecommitdiff
path: root/jstests/replsets/rename_collection_temp.js
diff options
context:
space:
mode:
authorBenjamin Murphy <benjamin_murphy@me.com>2016-03-22 16:37:12 -0400
committerBenjamin Murphy <benjamin_murphy@me.com>2016-03-24 18:11:16 -0400
commita19406fdedac2bff515a0b162c8d496b11f4e455 (patch)
tree5b0c43b5ac19f793d1c4c15da66d8f77eaa30624 /jstests/replsets/rename_collection_temp.js
parent0a412aaa51a81325465837e712faaaaaca27e922 (diff)
downloadmongo-a19406fdedac2bff515a0b162c8d496b11f4e455.tar.gz
SERVER-23274 renameCollection on a temporary collection correctly replicates.
Diffstat (limited to 'jstests/replsets/rename_collection_temp.js')
-rw-r--r--jstests/replsets/rename_collection_temp.js78
1 files changed, 78 insertions, 0 deletions
diff --git a/jstests/replsets/rename_collection_temp.js b/jstests/replsets/rename_collection_temp.js
new file mode 100644
index 00000000000..3add505a4f6
--- /dev/null
+++ b/jstests/replsets/rename_collection_temp.js
@@ -0,0 +1,78 @@
+// In SERVER-23274, the renameCollection command was found to incorrectly swap the "dropTarget" and
+// "stayTemp" arguments when run on a replica set. In this test, we check that the arguments are
+// correctly propagated.
+
+(function() {
+ "use strict";
+
+ function checkCollectionTemp(db, collName, expectedTempValue) {
+ var collectionInformation = db.getCollectionInfos();
+
+ var hasSeenCollection = false;
+ for (var i = 0; i < collectionInformation.length; i++) {
+ var collection = collectionInformation[i];
+
+ if (collection.name === collName) {
+ hasSeenCollection = true;
+
+ if (expectedTempValue) {
+ // We expect this collection to be temporary.
+ assert.eq(collection.options.temp, true);
+ } else {
+ // We expect this collection to be permanent, thus the temp option will not show
+ // up.
+ assert.isnull(collection.options.temp);
+ }
+ }
+ }
+ }
+
+ var replTest = new ReplSetTest({name: 'renameCollectionTest', nodes: 2});
+ var nodes = replTest.startSet();
+
+ replTest.initiate();
+
+ var master = replTest.getPrimary();
+
+ // Create a temporary collection.
+ var dbFoo = master.getDB("foo");
+
+ assert.commandWorked(dbFoo.runCommand({create: "tempColl", temp: true}));
+ checkCollectionTemp(dbFoo, "tempColl", true);
+
+ // Rename the collection.
+ assert.commandWorked(
+ master.adminCommand({renameCollection: "foo.tempColl", to: "foo.permanentColl"}));
+
+ // Confirm that it is no longer temporary.
+ checkCollectionTemp(dbFoo, "permanentColl", false);
+
+ replTest.awaitReplication();
+
+ var secondary = replTest.getSecondary();
+ var secondaryFoo = secondary.getDB("foo");
+
+ secondaryFoo.permanentColl.setSlaveOk(true);
+
+ // Get the information on the secondary to ensure it was replicated correctly.
+ checkCollectionTemp(secondaryFoo, "permanentColl", false);
+
+ // Check the behavior when the "dropTarget" flag is passed to renameCollection.
+ dbFoo.permanentColl.drop();
+
+ assert.commandWorked(dbFoo.runCommand({create: "tempColl", temp: true}));
+ checkCollectionTemp(dbFoo, "tempColl", true);
+
+ // Construct an empty collection that will be dropped on rename.
+ assert.commandWorked(dbFoo.runCommand({create: "permanentColl"}));
+
+ // Rename, dropping "permanentColl" and replacing it.
+ assert.commandWorked(master.adminCommand(
+ {renameCollection: "foo.tempColl", to: "foo.permanentColl", dropTarget: true}));
+
+ checkCollectionTemp(dbFoo, "permanentColl", false);
+
+ replTest.awaitReplication();
+
+ checkCollectionTemp(secondaryFoo, "permanentColl", false);
+}());