summaryrefslogtreecommitdiff
path: root/jstests/noPassthroughWithMongod
diff options
context:
space:
mode:
authorGregory Noma <gregory.noma@gmail.com>2020-04-10 11:22:34 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-04-10 15:34:40 +0000
commit4adcb62e1be77edfd448e3091d307a368181cc9e (patch)
tree2cdfc98988e76374c6b6695d4b0fef799caf3931 /jstests/noPassthroughWithMongod
parentda923cf72003a34a45ce7775dd66ccd944da7d11 (diff)
downloadmongo-4adcb62e1be77edfd448e3091d307a368181cc9e.tar.gz
SERVER-47423 Take collection MODE_X locks instead of databse MODE_X lock in cloneCollectionAsCapped
Diffstat (limited to 'jstests/noPassthroughWithMongod')
-rw-r--r--jstests/noPassthroughWithMongod/clone_collection_as_capped_no_conflicts.js44
1 files changed, 44 insertions, 0 deletions
diff --git a/jstests/noPassthroughWithMongod/clone_collection_as_capped_no_conflicts.js b/jstests/noPassthroughWithMongod/clone_collection_as_capped_no_conflicts.js
new file mode 100644
index 00000000000..b1deedfa1d0
--- /dev/null
+++ b/jstests/noPassthroughWithMongod/clone_collection_as_capped_no_conflicts.js
@@ -0,0 +1,44 @@
+/**
+ * Tests that cloneCollectionAsCapped does not conflict with a database MODE_IX lock.
+ */
+(function() {
+"use strict";
+
+load("jstests/libs/parallel_shell_helpers.js");
+load("jstests/libs/wait_for_command.js");
+
+const baseName = "clone_collection_as_capped_no_conflicts";
+const fromCollName = baseName + "_from";
+const toCollName = baseName + "_to";
+
+const testDB = db.getSiblingDB("test");
+testDB.dropDatabase();
+const fromColl = testDB.getCollection(fromCollName);
+const toColl = testDB.getCollection(toCollName);
+
+const sleepFunction = function(sleepDB) {
+ // If cloneCollectionAsCapped calls need to wait on this lock, holding this lock for 4 hours
+ // will trigger a test timeout.
+ assert.commandFailedWithCode(
+ db.getSiblingDB("test").adminCommand(
+ {sleep: 1, secs: 18000, lockTarget: sleepDB, lock: "iw", $comment: "Lock sleep"}),
+ ErrorCodes.Interrupted);
+};
+
+const sleepCommand = startParallelShell(funWithArgs(sleepFunction, "test"), testDB.getMongo().port);
+const sleepID =
+ waitForCommand("sleepCmd",
+ op => (op["ns"] == "admin.$cmd" && op["command"]["$comment"] == "Lock sleep"),
+ testDB.getSiblingDB("admin"));
+
+assert.commandWorked(fromColl.insert({a: 1}));
+assert(!fromColl.isCapped());
+assert.commandWorked(testDB.runCommand(
+ {cloneCollectionAsCapped: fromCollName, toCollection: toCollName, size: 100}));
+assert(toColl.isCapped());
+assert.eq(toColl.count(), 1);
+
+// Interrupt the sleep command.
+assert.commandWorked(testDB.getSiblingDB("admin").killOp(sleepID));
+sleepCommand();
+})(); \ No newline at end of file