summaryrefslogtreecommitdiff
path: root/jstests/noPassthroughWithMongod/captrunc_cursor_invalidation.js
diff options
context:
space:
mode:
authorDavid Storch <david.storch@10gen.com>2018-11-28 17:25:24 -0500
committerDavid Storch <david.storch@10gen.com>2019-01-15 17:54:33 -0500
commitde2a803ca492261cac1d7f43a9f7c847cd0ea24d (patch)
tree03cb6ea2b304463e7458f557246a95978d1ef96a /jstests/noPassthroughWithMongod/captrunc_cursor_invalidation.js
parentaf8fa6034f8a989cb47ee890c6a6b3e87e1bcf7b (diff)
downloadmongo-de2a803ca492261cac1d7f43a9f7c847cd0ea24d.tar.gz
SERVER-37451 Move all ClientCursor ownership to the global CursorManager.
Deleting the per-collection CursorManagers, and other related cleanup, is left as future work.
Diffstat (limited to 'jstests/noPassthroughWithMongod/captrunc_cursor_invalidation.js')
-rw-r--r--jstests/noPassthroughWithMongod/captrunc_cursor_invalidation.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/jstests/noPassthroughWithMongod/captrunc_cursor_invalidation.js b/jstests/noPassthroughWithMongod/captrunc_cursor_invalidation.js
new file mode 100644
index 00000000000..3b1f7337133
--- /dev/null
+++ b/jstests/noPassthroughWithMongod/captrunc_cursor_invalidation.js
@@ -0,0 +1,37 @@
+// Test that when a capped collection is truncated, tailable cursors die on getMore with the error
+// code 'CappedPositionLost'.
+//
+// @tags: [requires_capped]
+(function() {
+ "use strict";
+
+ const coll = db.captrunc_cursor_invalidation;
+ coll.drop();
+
+ // Create a capped collection with four documents.
+ assert.commandWorked(db.createCollection(coll.getName(), {capped: true, size: 1024}));
+ const numDocs = 4;
+ const bulk = coll.initializeUnorderedBulkOp();
+ for (let i = 0; i < numDocs; ++i) {
+ bulk.insert({_id: i});
+ }
+ assert.commandWorked(bulk.execute());
+
+ // Open a tailable cursor against the capped collection.
+ const findRes = assert.commandWorked(db.runCommand({find: coll.getName(), tailable: true}));
+ assert.neq(findRes.cursor.id, 0);
+ assert.eq(findRes.cursor.ns, coll.getFullName());
+ assert.eq(findRes.cursor.firstBatch.length, 4);
+ const cursorId = findRes.cursor.id;
+
+ // Truncate the capped collection so that the cursor's position no longer exists.
+ assert.commandWorked(db.runCommand({captrunc: coll.getName(), n: 2}));
+
+ // A subsequent getMore should fail with 'CappedPositionLost'.
+ assert.commandFailedWithCode(db.runCommand({getMore: cursorId, collection: coll.getName()}),
+ ErrorCodes.CappedPositionLost);
+
+ // The cursor has now been destroyed, so another getMore should fail with 'CursorNotFound'.
+ assert.commandFailedWithCode(db.runCommand({getMore: cursorId, collection: coll.getName()}),
+ ErrorCodes.CursorNotFound);
+}());