summaryrefslogtreecommitdiff
path: root/jstests/noPassthroughWithMongod
diff options
context:
space:
mode:
authorDianna Hohensee <dianna.hohensee@mongodb.com>2021-12-01 00:16:47 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-12-01 01:07:30 +0000
commit9fbeb1ef84dbe8cdcf331c00c8ef1d31ff949a6d (patch)
tree07e718c451934e2959423ad23fc640a559d16b0f /jstests/noPassthroughWithMongod
parentdfce26e49c0c124db64cab66036bfd92388fc31d (diff)
downloadmongo-9fbeb1ef84dbe8cdcf331c00c8ef1d31ff949a6d.tar.gz
SERVER-59667 Test tailable cursors across yield and getMore cmds
Diffstat (limited to 'jstests/noPassthroughWithMongod')
-rw-r--r--jstests/noPassthroughWithMongod/tailable_cursors_across_yield_and_getMore.js76
1 files changed, 76 insertions, 0 deletions
diff --git a/jstests/noPassthroughWithMongod/tailable_cursors_across_yield_and_getMore.js b/jstests/noPassthroughWithMongod/tailable_cursors_across_yield_and_getMore.js
new file mode 100644
index 00000000000..5bf62f0cdd0
--- /dev/null
+++ b/jstests/noPassthroughWithMongod/tailable_cursors_across_yield_and_getMore.js
@@ -0,0 +1,76 @@
+/**
+ * Tests that tailable cursors work correctly across query yield and getMore commands.
+ *
+ * This test is trying to check that internal server cursors remain valid across yield and getMore
+ * commands for the SBE query engine.
+ */
+
+(function() {
+"use strict";
+
+// Create a capped collection with max of 20 documents.
+const mydb = db.getSiblingDB(jsTestName() + "_db");
+const mycoll = mydb.getCollection(jsTestName() + "_coll");
+mycoll.drop();
+assert.commandWorked(mydb.createCollection(mycoll.getName(), {capped: true, size: 4096, max: 20}));
+
+// Insert 10 documents.
+const numDocs = 10;
+for (let i = 0; i < numDocs; ++i) {
+ assert.commandWorked(mycoll.insert({_id: i}));
+}
+
+// Set query to yield after every document read, so yielding is exercised at much as possible in the
+// subsequent find and getMore commands.
+const setParamResWas =
+ assert.commandWorked(db.adminCommand({setParameter: 1, internalQueryExecYieldIterations: 1}))
+ .was;
+
+try {
+ assert.eq(numDocs % 2, 0);
+ const batchSizeVal = numDocs / 2;
+
+ // Fetch the first half of the documents with a find cmd.
+ let cmdRes = mydb.runCommand({find: mycoll.getName(), batchSize: batchSizeVal, tailable: true});
+ const originalCursorId = cmdRes.cursor.id;
+ assert.commandWorked(cmdRes);
+ assert.gt(cmdRes.cursor.id, NumberLong(0));
+ assert.eq(cmdRes.cursor.ns, mycoll.getFullName());
+ assert.eq(cmdRes.cursor.firstBatch.length, 5);
+
+ // Fetch the next half of the documents with a getMore cmd.
+ cmdRes = mydb.runCommand({getMore: cmdRes.cursor.id, collection: mycoll.getName()});
+ assert.commandWorked(cmdRes);
+ assert.eq(cmdRes.cursor.id, originalCursorId);
+ assert.gt(cmdRes.cursor.id, NumberLong(0));
+ assert.eq(cmdRes.cursor.ns, mycoll.getFullName());
+ assert.eq(cmdRes.cursor.nextBatch.length, 5);
+
+ // Try to fetch more documents, but find none.
+ cmdRes = mydb.runCommand({getMore: cmdRes.cursor.id, collection: mycoll.getName()});
+ assert.commandWorked(cmdRes);
+ assert.gt(cmdRes.cursor.id, NumberLong(0));
+ assert.eq(cmdRes.cursor.id, originalCursorId);
+ assert.eq(cmdRes.cursor.ns, mycoll.getFullName());
+ assert.eq(cmdRes.cursor.nextBatch.length, 0);
+
+ // Insert less than 'batchSizeVal' more documents to find with another getMore command.
+ const nextBatchSize = batchSizeVal - 1;
+ for (let i = numDocs; i < numDocs + nextBatchSize; ++i) {
+ assert.commandWorked(mycoll.insert({_id: i}));
+ }
+
+ // Fetch all the remaining documents that can be found.
+ cmdRes = mydb.runCommand({getMore: cmdRes.cursor.id, collection: mycoll.getName()});
+ assert.commandWorked(cmdRes);
+ assert.gt(cmdRes.cursor.id, NumberLong(0));
+ assert.eq(cmdRes.cursor.id, originalCursorId);
+ assert.eq(cmdRes.cursor.ns, mycoll.getFullName());
+ assert.eq(cmdRes.cursor.nextBatch.length, nextBatchSize);
+} finally {
+ // We must ensure that the mongod's original settings are returned because this test shares a
+ // common mongod instance with other tests.
+ assert.commandWorked(
+ db.adminCommand({setParameter: 1, internalQueryExecYieldIterations: setParamResWas}));
+}
+})();