Skip to content

Commit 5684094

Browse files
committed
Small fix to make each work better with tailable cursors
1 parent 378051a commit 5684094

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

lib/cursor.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,7 @@ var nextObject = function(self, callback) {
633633
return handleCallback(callback, err);
634634
}
635635
}
636+
636637
// Get the next object
637638
self._next(function(err, doc) {
638639
if(err && err.tailable && self.s.currentNumberOfRetries == 0) return callback(err);
@@ -716,7 +717,7 @@ var _each = function(self, callback) {
716717
while(fn = loop(self, callback)) fn(self, callback);
717718
_each(self, callback);
718719
} else {
719-
self._next(function(err, item) {
720+
self.next(function(err, item) {
720721
if(err) return handleCallback(callback, err);
721722
if(item == null) {
722723
self.s.state = Cursor.CLOSED;

test/functional/cursor_tests.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2076,6 +2076,39 @@ exports.shouldNotAwaitDataWhenFalse = {
20762076
}
20772077
}
20782078

2079+
/**
2080+
* @ignore
2081+
*/
2082+
exports['Should correctly retry tailable cursor connection'] = {
2083+
// Add a tag that our runner can trigger on
2084+
// in this case we are setting that node needs to be higher than 0.10.X to run
2085+
metadata: { requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] } },
2086+
2087+
// The actual test we wish to run
2088+
test: function(configuration, test) {
2089+
// http://www.mongodb.org/display/DOCS/Tailable+Cursors
2090+
var db = configuration.newDbInstance(configuration.writeConcernMax(), {poolSize:1, auto_reconnect:false});
2091+
2092+
db.open(function(err, db) {
2093+
var options = { capped: true, size: 8};
2094+
db.createCollection('should_await_data', options, function(err, collection) {
2095+
collection.insert({a:1}, configuration.writeConcernMax(), function(err, result) {
2096+
var s = new Date();
2097+
// Create cursor with awaitdata, and timeout after the period specified
2098+
collection.find({}, {tailable:true, awaitdata:true, numberOfRetries:3, tailableRetryInterval:1000}).each(function(err, result) {
2099+
if(err != null) {
2100+
var e = new Date();
2101+
test.ok((e.getTime() - s.getTime()) >= 3000);
2102+
db.close();
2103+
test.done();
2104+
}
2105+
});
2106+
});
2107+
});
2108+
});
2109+
}
2110+
}
2111+
20792112
/**
20802113
* @ignore
20812114
*/

0 commit comments

Comments
 (0)