summaryrefslogtreecommitdiff
path: root/jstests
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
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')
-rw-r--r--jstests/auth/getMore.js7
-rw-r--r--jstests/core/getmore_invalidated_cursors.js42
-rw-r--r--jstests/core/operation_latency_histogram.js10
-rw-r--r--jstests/core/profile_getmore.js1
-rw-r--r--jstests/core/restart_catalog.js2
-rw-r--r--jstests/core/tailable_cursor_invalidation.js6
-rw-r--r--jstests/noPassthrough/commands_handle_kill.js4
-rw-r--r--jstests/noPassthroughWithMongod/captrunc_cursor_invalidation.js37
8 files changed, 70 insertions, 39 deletions
diff --git a/jstests/auth/getMore.js b/jstests/auth/getMore.js
index e232b52bb35..49c60fcf6ca 100644
--- a/jstests/auth/getMore.js
+++ b/jstests/auth/getMore.js
@@ -91,10 +91,9 @@
cursorId = res.cursor.id;
testDB.logout();
assert.eq(1, testDB.auth("Mallory", "pwd"));
- assert.commandFailedWithCode(
- testDB.runCommand({getMore: cursorId, collection: "$cmd.listIndexes.foo"}),
- ErrorCodes.Unauthorized,
- "read from another user's listIndexes cursor");
+ assert.commandFailedWithCode(testDB.runCommand({getMore: cursorId, collection: "foo"}),
+ ErrorCodes.Unauthorized,
+ "read from another user's listIndexes cursor");
testDB.logout();
//
diff --git a/jstests/core/getmore_invalidated_cursors.js b/jstests/core/getmore_invalidated_cursors.js
index 788fb662cba..c244b071716 100644
--- a/jstests/core/getmore_invalidated_cursors.js
+++ b/jstests/core/getmore_invalidated_cursors.js
@@ -45,7 +45,7 @@
// The cursor will be invalidated on mongos, and we won't be able to find it.
assert.neq(-1, error.message.indexOf('didn\'t exist on server'), error.message);
} else {
- assert.eq(error.code, ErrorCodes.OperationFailed, tojson(error));
+ assert.eq(error.code, ErrorCodes.QueryPlanKilled, tojson(error));
assert.neq(-1, error.message.indexOf('collection dropped'), error.message);
}
@@ -56,29 +56,31 @@
cursor.next(); // Send the query to the server.
coll.drop();
-
error = assert.throws(() => cursor.itcount());
- if (isShardedCollection) {
- // The cursor will be invalidated on mongos, and we won't be able to find it.
- if (shellReadMode == 'legacy') {
- assert.neq(-1, error.message.indexOf('didn\'t exist on server'), error.message);
- } else {
- assert.eq(error.code, ErrorCodes.CursorNotFound, tojson(error));
- assert.neq(-1, error.message.indexOf('not found'), error.message);
- }
- } else {
- assert.eq(error.code, ErrorCodes.OperationFailed, tojson(error));
- assert.neq(-1, error.message.indexOf('collection dropped'), error.message);
- }
-
- // Test that dropping an index between a find and a getMore will return an appropriate error
- // code and message.
+ assert.eq(error.code, ErrorCodes.QueryPlanKilled, tojson(error));
+ // In replica sets, collection drops are done in two phases, first renaming the collection to a
+ // "drop pending" namespace, and then later reaping the collection. Therefore, we expect to
+ // either see an error message related to a collection drop, or one related to a collection
+ // rename.
+ const droppedMsg = 'collection dropped';
+ const renamedMsg = 'collection renamed';
+ assert(-1 !== error.message.indexOf(droppedMsg) || -1 !== error.message.indexOf(renamedMsg),
+ error.message);
+
+ // Test that dropping an index between a find and a getMore has no effect on the query if the
+ // query is not using the index.
setupCollection();
cursor = coll.find().batchSize(batchSize);
cursor.next(); // Send the query to the server.
-
assert.commandWorked(testDB.runCommand({dropIndexes: coll.getName(), index: {x: 1}}));
+ assert.eq(cursor.itcount(), nDocs - 1);
+ // Test that dropping the index being scanned by a cursor between a find and a getMore kills the
+ // query with the appropriate code and message.
+ setupCollection();
+ cursor = coll.find().hint({x: 1}).batchSize(batchSize);
+ cursor.next(); // Send the query to the server.
+ assert.commandWorked(testDB.runCommand({dropIndexes: coll.getName(), index: {x: 1}}));
error = assert.throws(() => cursor.itcount());
assert.eq(error.code, ErrorCodes.QueryPlanKilled, tojson(error));
assert.neq(-1, error.message.indexOf('index \'x_1\' dropped'), error.message);
@@ -111,8 +113,8 @@
// Ensure getMore fails with an appropriate error code and message.
error = assert.throws(() => cursor.itcount());
- assert.eq(error.code, ErrorCodes.OperationFailed, tojson(error));
- assert.neq(-1, error.message.indexOf('collection dropped'), error.message);
+ assert.eq(error.code, ErrorCodes.QueryPlanKilled, tojson(error));
+ assert.neq(-1, error.message.indexOf('collection renamed'), error.message);
}
}());
diff --git a/jstests/core/operation_latency_histogram.js b/jstests/core/operation_latency_histogram.js
index a8f0800b327..d3bce1305c9 100644
--- a/jstests/core/operation_latency_histogram.js
+++ b/jstests/core/operation_latency_histogram.js
@@ -81,15 +81,7 @@
for (var i = 0; i < numRecords - 1; i++) {
cursors[i].close();
}
- try {
- // Each close may result in two commands in latencyStats due to separate
- // pinning during auth check and execution.
- lastHistogram = assertHistogramDiffEq(testColl, lastHistogram, 0, 0, 2 * (numRecords - 1));
- } catch (e) {
- // Increment last reads to account for extra getstats call
- ++lastHistogram.reads.ops;
- lastHistogram = assertHistogramDiffEq(testColl, lastHistogram, 0, 0, numRecords - 1);
- }
+ lastHistogram = assertHistogramDiffEq(testColl, lastHistogram, 0, 0, numRecords - 1);
// Remove
for (var i = 0; i < numRecords; i++) {
diff --git a/jstests/core/profile_getmore.js b/jstests/core/profile_getmore.js
index 344800dc011..74c62f0176b 100644
--- a/jstests/core/profile_getmore.js
+++ b/jstests/core/profile_getmore.js
@@ -45,6 +45,7 @@
assert.eq(profileObj.originatingCommand.filter, {a: {$gt: 0}});
assert.eq(profileObj.originatingCommand.sort, {a: 1});
assert.eq(profileObj.planSummary, "IXSCAN { a: 1 }", tojson(profileObj));
+ assert(profileObj.hasOwnProperty("execStats"), tojson(profileObj));
assert(profileObj.execStats.hasOwnProperty("stage"), tojson(profileObj));
assert(profileObj.hasOwnProperty("responseLength"), tojson(profileObj));
assert(profileObj.hasOwnProperty("numYield"), tojson(profileObj));
diff --git a/jstests/core/restart_catalog.js b/jstests/core/restart_catalog.js
index 239c69f5e07..19bd0f9f27c 100644
--- a/jstests/core/restart_catalog.js
+++ b/jstests/core/restart_catalog.js
@@ -134,5 +134,5 @@
assert.commandFailedWithCode(
secondTestDB.runCommand(
{getMore: cursorResponse.cursor.id, collection: foodColl.getName()}),
- ErrorCodes.CursorNotFound);
+ ErrorCodes.QueryPlanKilled);
}());
diff --git a/jstests/core/tailable_cursor_invalidation.js b/jstests/core/tailable_cursor_invalidation.js
index 856dfc9c5c4..97ea96bb8d0 100644
--- a/jstests/core/tailable_cursor_invalidation.js
+++ b/jstests/core/tailable_cursor_invalidation.js
@@ -60,13 +60,13 @@
return findRes.cursor.id;
}
- // Test that a cursor cannot be found if a collection is dropped between a find and a getMore.
+ // Test that the cursor dies on getMore if the collection has been dropped.
let cursorId = openCursor({tailable: true, awaitData: false});
dropAndRecreateColl();
assert.commandFailedWithCode(db.runCommand({getMore: cursorId, collection: collName}),
- ErrorCodes.CursorNotFound);
+ ErrorCodes.QueryPlanKilled);
cursorId = openCursor({tailable: true, awaitData: true});
dropAndRecreateColl();
assert.commandFailedWithCode(db.runCommand({getMore: cursorId, collection: collName}),
- ErrorCodes.CursorNotFound);
+ ErrorCodes.QueryPlanKilled);
}());
diff --git a/jstests/noPassthrough/commands_handle_kill.js b/jstests/noPassthrough/commands_handle_kill.js
index 884f57a5d04..799cfc8cca1 100644
--- a/jstests/noPassthrough/commands_handle_kill.js
+++ b/jstests/noPassthrough/commands_handle_kill.js
@@ -87,8 +87,8 @@
// These are commands that will cause all running PlanExecutors to be invalidated, and the
// error messages that should be propagated when that happens.
const invalidatingCommands = [
- {command: {dropDatabase: 1}, message: 'Collection dropped'},
- {command: {drop: collName}, message: 'Collection dropped'},
+ {command: {dropDatabase: 1}, message: 'collection dropped'},
+ {command: {drop: collName}, message: 'collection dropped'},
];
if (options.usesIndex) {
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);
+}());