summaryrefslogtreecommitdiff
path: root/jstests/noPassthroughWithMongod
diff options
context:
space:
mode:
authorGregory Noma <gregory.noma@gmail.com>2020-04-10 09:26:58 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-04-10 13:45:41 +0000
commit9d4284a8010e35a640306017de895be568be4855 (patch)
treeb58eccc0f90289de961c0e0d83ff069b9a443a72 /jstests/noPassthroughWithMongod
parentd3da6de558fc4fbd7bb20617ed5d1f34c2c58bb3 (diff)
downloadmongo-9d4284a8010e35a640306017de895be568be4855.tar.gz
SERVER-47317 Take collection MODE_X locks instead of database MODE_X lock in covertToCapped
(cherry picked from commit ff483e300c692dd2a47a649c4bddc3632178b2fd)
Diffstat (limited to 'jstests/noPassthroughWithMongod')
-rw-r--r--jstests/noPassthroughWithMongod/convert_to_capped_no_conflicts.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/jstests/noPassthroughWithMongod/convert_to_capped_no_conflicts.js b/jstests/noPassthroughWithMongod/convert_to_capped_no_conflicts.js
new file mode 100644
index 00000000000..f037b0075ee
--- /dev/null
+++ b/jstests/noPassthroughWithMongod/convert_to_capped_no_conflicts.js
@@ -0,0 +1,38 @@
+/**
+ * Tests that convertToCapped 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 collName = "convert_to_capped_no_conflicts";
+const testDB = db.getSiblingDB("test");
+testDB.dropDatabase();
+const testColl = testDB.getCollection(collName);
+
+const sleepFunction = function(sleepDB) {
+ // If convertToCapped 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(testColl.insert({a: 1}));
+assert(!testColl.isCapped());
+assert.commandWorked(testDB.runCommand({convertToCapped: collName, size: 1}));
+assert(testColl.isCapped());
+
+// Interrupt the sleep command.
+assert.commandWorked(testDB.getSiblingDB("admin").killOp(sleepID));
+sleepCommand();
+})(); \ No newline at end of file