Skip to content

Commit af66afc

Browse files
committed
added attempt to cause cursor failure
1 parent 3d07d02 commit af66afc

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

test/functional/find_tests.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2256,3 +2256,48 @@ exports['Should correctly execute parallelCollectionScan with single cursor emit
22562256
});
22572257
}
22582258
}
2259+
2260+
exports['Should simulate closed cursor'] = {
2261+
// Add a tag that our runner can trigger on
2262+
// in this case we are setting that node needs to be higher than 0.10.X to run
2263+
metadata: { requires: { mongodb: ">2.5.5", topology: ["single", "replicaset"] } },
2264+
2265+
// The actual test we wish to run
2266+
test: function(configuration, test) {
2267+
var db = configuration.newDbInstance(configuration.writeConcernMax(), {poolSize:1, auto_reconnect:false});
2268+
// Establish connection to db
2269+
db.open(function(err, db) {
2270+
var docs = [];
2271+
2272+
// Insert some documents
2273+
for(var i = 0; i < 1000; i++) {
2274+
docs.push({a:i});
2275+
}
2276+
2277+
// Get the collection
2278+
var collection = db.collection('parallelCollectionScan_4');
2279+
// Insert 1000 documents in a batch
2280+
collection.insert(docs, function(err, result) {
2281+
var results = [];
2282+
var numCursors = 1;
2283+
2284+
// Get the cursor
2285+
var cursor = collection.find({}).batchSize(2);
2286+
// Get next document
2287+
cursor.next(function(err, doc) {
2288+
test.equal(null, err);
2289+
test.ok(doc != null);
2290+
2291+
// Mess with state forcing a call to isDead on the cursor
2292+
cursor.s.state = 2;
2293+
2294+
cursor.next(function(err, doc) {
2295+
test.ok(err != null);
2296+
db.close();
2297+
test.done();
2298+
})
2299+
});
2300+
});
2301+
});
2302+
}
2303+
}

0 commit comments

Comments
 (0)