Skip to content

Commit

Permalink
SERVER-21602 Use 'cursorTimeoutMillis' flag in cursor_timeout.js
Browse files Browse the repository at this point in the history
Reduces this test's execution time from ~17 minutes to <30 seconds.
  • Loading branch information
jrassi committed Dec 8, 2015
1 parent fc69c3d commit 181cdbf
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions 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;
Expand All @@ -21,7 +36,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 ));
Expand All @@ -45,21 +60,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();

0 comments on commit 181cdbf

Please sign in to comment.