summaryrefslogtreecommitdiff
path: root/jstests/slowWeekly/cursor_timeout.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/slowWeekly/cursor_timeout.js')
-rw-r--r--jstests/slowWeekly/cursor_timeout.js61
1 files changed, 61 insertions, 0 deletions
diff --git a/jstests/slowWeekly/cursor_timeout.js b/jstests/slowWeekly/cursor_timeout.js
new file mode 100644
index 00000000000..c8ad33c3849
--- /dev/null
+++ b/jstests/slowWeekly/cursor_timeout.js
@@ -0,0 +1,61 @@
+var st = new ShardingTest({ shards: 2, other: { chunkSize: 1 }});
+st.stopBalancer();
+
+var adminDB = st.admin;
+var configDB = st.config;
+var coll = st.s.getDB( 'test' ).user;
+
+adminDB.runCommand({ enableSharding: coll.getDB().getName() });
+adminDB.runCommand({ shardCollection: coll.getFullName(), key: { x: 1 }});
+
+var data = 'c';
+for( var x = 0; x < 18; x++ ){
+ data += data;
+}
+
+for( x = 0; x < 200; x++ ){
+ coll.insert({ x: x, v: data });
+}
+
+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 res = adminDB.runCommand( cmd );
+
+jsTest.log( 'move result: ' + tojson( res ));
+
+var shardedCursorWithTimeout = coll.find();
+var shardedCursorWithNoTimeout = coll.find();
+shardedCursorWithNoTimeout.addOption( DBQuery.Option.noTimeout );
+
+// Query directly to mongod
+var shardHost = configDB.shards.findOne({ _id: chunkOwner }).host;
+var mongod = new Mongo( shardHost );
+var shardColl = mongod.getCollection( coll.getFullName() );
+
+var cursorWithTimeout = shardColl.find();
+var cursorWithNoTimeout = shardColl.find();
+cursorWithNoTimeout.addOption( DBQuery.Option.noTimeout );
+
+shardedCursorWithTimeout.next();
+shardedCursorWithNoTimeout.next();
+
+cursorWithTimeout.next();
+cursorWithNoTimeout.next();
+
+// Cursor cleanup is 10 minutes, but give a 1 min allowance
+sleep( 660000 );
+
+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 );
+
+var freshItCount = shardColl.find().itcount();
+assert.eq( freshItCount, cursorWithNoTimeout.itcount() + 1 );
+
+st.stop();
+