Skip to content

Commit 0bfde22

Browse files
committed
NODE-957 Added cursor test that shows cursor closed when batchSize < 0
1 parent 791728e commit 0bfde22

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

test/functional/cursor_tests.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3259,3 +3259,48 @@ exports['Should correctly execute count on cursor with limit and skip'] = {
32593259
});
32603260
}
32613261
}
3262+
3263+
/**
3264+
* @ignore
3265+
* @api private
3266+
*/
3267+
exports['Should correctly handle negative batchSize and set the limit'] = {
3268+
// Add a tag that our runner can trigger on
3269+
// in this case we are setting that node needs to be higher than 0.10.X to run
3270+
metadata: { requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] } },
3271+
3272+
// The actual test we wish to run
3273+
test: function(configuration, test) {
3274+
var docs = [];
3275+
var Long = configuration.require.Long;
3276+
3277+
for(var i = 0; i < 50; i++) {
3278+
var d = new Date().getTime() + i*1000;
3279+
docs[i] = {'a':i, createdAt:new Date(d)};
3280+
}
3281+
3282+
var db = configuration.newDbInstance(configuration.writeConcernMax(), {poolSize:1});
3283+
db.open(function(err, db) {
3284+
// Create collection
3285+
db.createCollection('Should_correctly_execute_count_on_cursor_1_', function(err, collection) {
3286+
test.equal(null, err);
3287+
3288+
// insert all docs
3289+
collection.insert(docs, configuration.writeConcernMax(), function(err, result) {
3290+
test.equal(null, err);
3291+
var total = 0;
3292+
3293+
// Create a cursor for the content
3294+
var cursor = collection.find({});
3295+
cursor.batchSize(-10).next(function(err, doc) {
3296+
test.equal(null, err);
3297+
test.ok(cursor.cursorState.cursorId.equals(Long.ZERO));
3298+
3299+
db.close();
3300+
test.done();
3301+
});
3302+
})
3303+
});
3304+
});
3305+
}
3306+
}

0 commit comments

Comments
 (0)