summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorTed Tuckman <ted.tuckman@mongodb.com>2018-10-05 09:43:25 -0400
committerTed Tuckman <ted.tuckman@mongodb.com>2018-10-05 16:44:20 -0400
commit2e313aa04c07080e0734e694f43f99f4bc8ddb94 (patch)
tree0db4853b0a550f3847317ae9cc8e90a8780cfb20 /jstests
parent4579024b52313547fd478545fd1cd2649f658939 (diff)
downloadmongo-2e313aa04c07080e0734e694f43f99f4bc8ddb94.tar.gz
SERVER-37486 Prevent race in currentop_cursors.js
Diffstat (limited to 'jstests')
-rw-r--r--jstests/core/currentop_cursors.js65
1 files changed, 42 insertions, 23 deletions
diff --git a/jstests/core/currentop_cursors.js b/jstests/core/currentop_cursors.js
index e8fad63f8bb..46c7806458a 100644
--- a/jstests/core/currentop_cursors.js
+++ b/jstests/core/currentop_cursors.js
@@ -11,7 +11,7 @@
// Avoiding using the shell helper to avoid the implicit collection recreation.
db.runCommand({drop: coll.getName()});
assert.commandWorked(db.createCollection(coll.getName(), {capped: true, size: 1000}));
- for (let i = 0; i < 5; ++i) {
+ for (let i = 0; i < 30; ++i) {
assert.commandWorked(coll.insert({"val": i}));
}
/**
@@ -99,27 +99,28 @@
.cursor.id;
},
assertFunc: function(cursorId, result) {
- const secondCursor =
- assert.commandWorked(db.runCommand({find: "jstests_currentop", batchSize: 2}));
const adminDB = db.getSiblingDB("admin");
- const secondResult =
- adminDB
- .aggregate([
- {$currentOp: {localOps: true, allUsers: false, idleCursors: true}},
- {
- $match: {
- $and: [
- {type: "idleCursor"},
- {"cursor.cursorId": secondCursor.cursor.id}
- ]
- }
- }
- ])
- .toArray();
- assert.lt(result[0].cursor.createdDate, secondResult[0].cursor.createdDate, function() {
- return tojson(result) + tojson(secondResult);
- });
+ // Make sure the two cursors have different creation times.
+ assert.soon(() => {
+ const secondCursor =
+ assert.commandWorked(db.runCommand({find: "jstests_currentop", batchSize: 2}));
+ const secondResult =
+ adminDB
+ .aggregate([
+ {$currentOp: {localOps: true, allUsers: false, idleCursors: true}},
+ {
+ $match: {
+ $and: [
+ {type: "idleCursor"},
+ {"cursor.cursorId": secondCursor.cursor.id}
+ ]
+ }
+ }
+ ])
+ .toArray();
+ return result[0].cursor.createdDate < secondResult[0].cursor.createdDate;
+ });
}
});
@@ -157,12 +158,30 @@
{$match: {$and: [{type: "idleCursor"}, {"cursor.cursorId": cursorId}]}}
])
.toArray();
- const idleCursor = result[0].cursor;
+ let idleCursor = result[0].cursor;
assert.eq(idleCursor.nDocsReturned, 4, result);
assert.eq(idleCursor.nBatchesReturned, 2, result);
assert.eq(idleCursor.originatingCommand.batchSize, 2, result);
- assert.lt(idleCursor.createdDate, idleCursor.lastAccessDate, result);
- assert.lt(originalAccess, idleCursor.lastAccessDate, result);
+ // Make sure that the getMore will not finish running in the same milli as the cursor
+ // creation.
+ assert.soon(() => {
+ assert.commandWorked(db.runCommand(
+ {getMore: cursorId, collection: "jstests_currentop", batchSize: 2}));
+ result =
+ adminDB
+ .aggregate([
+ {$currentOp: {localOps: true, allUsers: false, idleCursors: true}},
+ {
+ $match:
+ {$and: [{type: "idleCursor"}, {"cursor.cursorId": cursorId}]}
+ }
+ ])
+ .toArray();
+ idleCursor = result[0].cursor;
+ return idleCursor.createdDate < idleCursor.lastAccessDate &&
+ originalAccess < idleCursor.lastAccessDate;
+
+ });
}
});