Skip to content

Commit 6787b16

Browse files
committed
NODE-839 test case showing working behavior
1 parent 3bf21ee commit 6787b16

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

test/functional/cursor_tests.js

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3165,3 +3165,95 @@ exports['Should not emit any events after close event emitted due to cursor kill
31653165
});
31663166
}
31673167
}
3168+
3169+
/**
3170+
* @ignore
3171+
* @api private
3172+
*/
3173+
exports.shouldCorrectlyExecuteEnsureIndexWithNoCallback = {
3174+
// Add a tag that our runner can trigger on
3175+
// in this case we are setting that node needs to be higher than 0.10.X to run
3176+
metadata: { requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] } },
3177+
3178+
// The actual test we wish to run
3179+
test: function(configuration, test) {
3180+
var docs = [];
3181+
3182+
for(var i = 0; i < 1; i++) {
3183+
var d = new Date().getTime() + i*1000;
3184+
docs[i] = {createdAt:new Date(d)};
3185+
}
3186+
3187+
var db = configuration.newDbInstance(configuration.writeConcernMax(), {poolSize:1});
3188+
db.open(function(err, db) {
3189+
// Create collection
3190+
db.createCollection('shouldCorrectlyExecuteEnsureIndexWithNoCallback', function(err, collection) {
3191+
// ensure index of createdAt index
3192+
collection.ensureIndex({createdAt:1}, function(err, result) {
3193+
// insert all docs
3194+
collection.insert(docs, configuration.writeConcernMax(), function(err, result) {
3195+
test.equal(null, err);
3196+
3197+
// Find with sort
3198+
collection.find().sort(['createdAt', 'asc']).toArray(function(err, items) {
3199+
test.equal(null, err);
3200+
test.equal(1, items.length);
3201+
db.close();
3202+
test.done();
3203+
})
3204+
})
3205+
});
3206+
});
3207+
});
3208+
}
3209+
}
3210+
3211+
/**
3212+
* @ignore
3213+
* @api private
3214+
*/
3215+
exports['Should correctly execute count on cursor with limit and skip'] = {
3216+
// Add a tag that our runner can trigger on
3217+
// in this case we are setting that node needs to be higher than 0.10.X to run
3218+
metadata: { requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] } },
3219+
3220+
// The actual test we wish to run
3221+
test: function(configuration, test) {
3222+
var docs = [];
3223+
3224+
for(var i = 0; i < 50; i++) {
3225+
var d = new Date().getTime() + i*1000;
3226+
docs[i] = {'a':i, createdAt:new Date(d)};
3227+
}
3228+
3229+
var db = configuration.newDbInstance(configuration.writeConcernMax(), {poolSize:1});
3230+
db.open(function(err, db) {
3231+
// Create collection
3232+
db.createCollection('Should_correctly_execute_count_on_cursor_1', function(err, collection) {
3233+
test.equal(null, err);
3234+
3235+
// insert all docs
3236+
collection.insert(docs, configuration.writeConcernMax(), function(err, result) {
3237+
test.equal(null, err);
3238+
var total = 0;
3239+
3240+
// Create a cursor for the content
3241+
var cursor = collection.find({});
3242+
cursor.limit(100).skip(0).count(function(err, c) {
3243+
test.equal(null, err);
3244+
test.equal(50, c);
3245+
3246+
var cursor = collection.find({});
3247+
cursor.limit(100).skip(0).toArray(function(err, docs) {
3248+
test.equal(null, err);
3249+
test.equal(50, c);
3250+
3251+
db.close();
3252+
test.done();
3253+
});
3254+
})
3255+
})
3256+
});
3257+
});
3258+
}
3259+
}

0 commit comments

Comments
 (0)