diff options
author | David Storch <david.storch@10gen.com> | 2015-12-11 13:19:56 -0500 |
---|---|---|
committer | David Storch <david.storch@10gen.com> | 2015-12-11 14:37:41 -0500 |
commit | 0ce05c7d8c4a7b309c9792d4350db680bdd7096d (patch) | |
tree | c5702f471ef4a118a1148daff5ded2f644b9f05e /jstests/core/kill_cursors.js | |
parent | bb7e1e539da115da4ee1146c79e47c23109dce95 (diff) | |
download | mongo-0ce05c7d8c4a7b309c9792d4350db680bdd7096d.tar.gz |
SERVER-21852 fix more flakiness in kill_cursors.js
Diffstat (limited to 'jstests/core/kill_cursors.js')
-rw-r--r-- | jstests/core/kill_cursors.js | 49 |
1 files changed, 32 insertions, 17 deletions
diff --git a/jstests/core/kill_cursors.js b/jstests/core/kill_cursors.js index 4e91848adc4..f413538670f 100644 --- a/jstests/core/kill_cursors.js +++ b/jstests/core/kill_cursors.js @@ -105,36 +105,51 @@ cursorId = cmdRes.cursor.id; assert.neq(cursorId, NumberLong(0)); - // Pin the cursor during a getMore, and wait to make sure it has been pinned. - var numPinnedBefore = db.serverStatus().metrics.cursor.open.pinned; + cmdRes = db.runCommand({isMaster: 1}); + assert.commandWorked(cmdRes); + var isMongos = (cmdRes.msg === "isdbgrid"); + + // Pin the cursor during a getMore. var code = 'db.runCommand({getMore: ' + cursorId.toString() + ', collection: "' + coll.getName() + '"});' cleanup = startParallelShell(code); - assert.soon(function() { - // It's possible that the internally issued queries (e.g. syncing from primary to - // secondary in a replica set) can cause an additional cursor to be pinned. This is why - // we check "> numPinnedBefore" rather than "== numPinnedBefore + 1". - return (db.serverStatus().metrics.cursor.open.pinned > numPinnedBefore); - }, "Failed to pin cursor. Cursors pinned before running getMore: " + numPinnedBefore); - cmdRes = db.runCommand({isMaster: 1}); - assert.commandWorked(cmdRes); - var isMongos = (cmdRes.msg === "isdbgrid"); + // Sleep to make it more likely that the cursor will be pinned. + sleep(2000); - // Attempt to kill a pinned cursor. Currently pinned cursors that are targeted by a - // killCursors operation are kept alive on mongod but are killed on mongos (see - // SERVER-21710). + // Attempt to kill the cursor. In order to avoid flakiness, we do not assume that the cursor + // is already pinned (although generally it will be). + // + // Currently, pinned cursors that are targeted by a killCursors operation are kept alive on + // mongod but are killed on mongos (see SERVER-21710). cmdRes = db.runCommand({ killCursors: coll.getName(), cursors: [NumberLong(123), cursorId] }); assert.commandWorked(cmdRes); - assert.eq(cmdRes.cursorsKilled, isMongos ? [cursorId] : []); assert.eq(cmdRes.cursorsNotFound, [NumberLong(123)]); - assert.eq(cmdRes.cursorsAlive, isMongos ? [] : [cursorId]); assert.eq(cmdRes.cursorsUnknown, []); + + if (isMongos) { + assert.eq(cmdRes.cursorsKilled, [cursorId]); + assert.eq(cmdRes.cursorsAlive, []); + } + else { + // If the cursor has already been pinned it will be left alive; otherwise it will be + // killed. + if (cmdRes.cursorsAlive.length === 1) { + assert.eq(cmdRes.cursorsKilled, []); + assert.eq(cmdRes.cursorsAlive, [cursorId]); + } + else { + assert.eq(cmdRes.cursorsKilled, [cursorId]); + assert.eq(cmdRes.cursorsAlive, []); + } + } } finally { assert.commandWorked(db.adminCommand({configureFailPoint: failpointName, mode: "off"})); - cleanup(); + if (cleanup) { + cleanup(); + } } })(); |