diff options
-rw-r--r-- | jstests/slow2/cursor_timeout.js | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/jstests/slow2/cursor_timeout.js b/jstests/slow2/cursor_timeout.js index 3e80e6c6fa7..d453713bb9d 100644 --- a/jstests/slow2/cursor_timeout.js +++ b/jstests/slow2/cursor_timeout.js @@ -1,4 +1,19 @@ -var st = new ShardingTest({ shards: 2, other: { chunkSize: 1 }}); +// Basic integration tests for the background job that periodically kills idle cursors, in both +// mongod and mongos. This test creates the following four cursors: +// +// 1. A no-timeout cursor through mongos. +// 2. A no-timeout cursor through mongod. +// 3. A normal cursor through mongos. +// 4. A normal cursor through mongod. +// +// After a period of inactivity, the test asserts that cursors #1 and #2 are still alive, and that +// #3 and #4 have been killed. + +var st = + new ShardingTest( { shards: 2, + other: { chunkSize: 1, + shardOptions: { setParameter: "cursorTimeoutMillis=1000" }, + mongosOptions: { setParameter: "cursorTimeoutMillis=1000" } } } ); st.stopBalancer(); var adminDB = st.admin; @@ -20,7 +35,7 @@ for( x = 0; x < 200; x++ ){ var chunkDoc = configDB.chunks.findOne(); var chunkOwner = chunkDoc.shard; var toShard = configDB.shards.findOne({ _id: { $ne: chunkOwner }})._id; -var cmd = { moveChunk: coll.getFullName(), find: chunkDoc.min, to: toShard }; +var cmd = { moveChunk: coll.getFullName(), find: chunkDoc.min, to: toShard, _waitForDelete: true }; var res = adminDB.runCommand( cmd ); jsTest.log( 'move result: ' + tojson( res )); @@ -44,21 +59,18 @@ shardedCursorWithNoTimeout.next(); cursorWithTimeout.next(); cursorWithNoTimeout.next(); -// Cursor cleanup is 10 minutes, but give a 8 min allowance -- -// NOTE: Due to inaccurate timing on non-Linux platforms, mongos tries -// to timeout after 10 minutes but in fact is 15+ minutes; -// SERVER-8381 -sleep( 1000 * 60 * 17 ); +// Wait until the idle cursor background job has killed the cursors that do not have the "no +// timeout" flag set. We use the "cursorTimeoutMillis" setParameter above to reduce the amount of +// time we need to wait here. +sleep( 5000 ); assert.throws( function(){ shardedCursorWithTimeout.itcount(); } ); assert.throws( function(){ cursorWithTimeout.itcount(); } ); -var freshShardedItCount = coll.find().itcount(); // +1 because we already advanced once -assert.eq( freshShardedItCount, shardedCursorWithNoTimeout.itcount() + 1 ); +assert.eq( coll.count(), shardedCursorWithNoTimeout.itcount() + 1 ); -var freshItCount = shardColl.find().itcount(); -assert.eq( freshItCount, cursorWithNoTimeout.itcount() + 1 ); +assert.eq( shardColl.count(), cursorWithNoTimeout.itcount() + 1 ); st.stop(); |