Merge pull request #164 from TomV/fix-io-starving-problem

Fix the nextTick(cb) causing event loop starvation
pull/2/head
Louis Chatriot 10 years ago
commit 3abfa53b06
  1. 6
      lib/executor.js
  2. 21
      test/executor.test.js

@ -22,7 +22,11 @@ function Executor () {
// Always tell the queue task is complete. Execute callback if any was given.
if (typeof lastArg === 'function') {
callback = function () {
process.nextTick(cb);
if (typeof setImmediate === 'function') {
setImmediate(cb);
} else {
process.nextTick(cb);
}
lastArg.apply(null, arguments);
};

@ -74,7 +74,22 @@ function testRightOrder (d, done) {
});
}
// Note: The following test does not have any assertion because it
// is meant to address the deprecation warning:
// (node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.
// see
var testEventLoopStarvation = function(d, done){
var times = 1001;
var i = 0;
while ( i <times) {
i++;
d.find({"bogus": "search"}, function (err, docs) {
});
}
done();
};
describe('Executor', function () {
@ -113,6 +128,10 @@ describe('Executor', function () {
it('Operations are executed in the right order', function(done) {
testRightOrder(d, done);
});
it('Does not starve event loop and raise warning when more than 1000 callbacks are in queue', function(done){
testEventLoopStarvation(d, done);
});
}); // ==== End of 'With persistent database' ====

Loading…
Cancel
Save