Skip to content

Commit

Permalink
Last necessary test
Browse files Browse the repository at this point in the history
  • Loading branch information
louischatriot committed Feb 14, 2016
1 parent be83e8d commit 41827a5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/executor.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function Executor () {
}
lastArg.apply(null, arguments);
};
} else if (!lastArg && task.arguments.length) {
} else if (!lastArg && task.arguments.length !== 0) {
// false/undefined/null supplied as callbback
newArguments[newArguments.length - 1] = function () { cb(); };
} else {
Expand Down
33 changes: 25 additions & 8 deletions test/executor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function testThrowInCallback (d, done) {
});
}

//Test that if the callback is falsy, the next DB operations will still be executed
// Test that if the callback is falsy, the next DB operations will still be executed
function testFalsyCallback (d, done) {
d.insert({ a: 1 }, null);
process.nextTick(function () {
Expand All @@ -62,7 +62,7 @@ function testFalsyCallback (d, done) {
// We prevent Mocha from catching the exception we throw on purpose by remembering all current handlers, remove them and register them back after test ends
function testRightOrder (d, done) {
var currentUncaughtExceptionHandlers = process.listeners('uncaughtException');

process.removeAllListeners('uncaughtException');

process.on('uncaughtException', function (err) {
Expand Down Expand Up @@ -99,8 +99,6 @@ 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.
Expand All @@ -114,9 +112,20 @@ var testEventLoopStarvation = function(d, done){
});
}
done();
};
};

// Test that operations are executed in the right order even with no callback
function testExecutorWorksWithoutCallback (d, done) {
d.insert({ a: 1 });
d.insert({ a: 2 }, false);
d.find({}, function (err, docs) {
docs.length.should.equal(2);
done();
});
}

describe('Executor', function () {

describe.only('Executor', function () {

describe('With persistent database', function () {
var d;
Expand Down Expand Up @@ -161,7 +170,11 @@ describe('Executor', function () {
it('Does not starve event loop and raise warning when more than 1000 callbacks are in queue', function(done){
testEventLoopStarvation(d, done);
});


it('Works in the right order even with no supplied callback', function(done){
testExecutorWorksWithoutCallback(d, done);
});

}); // ==== End of 'With persistent database' ====


Expand Down Expand Up @@ -190,7 +203,11 @@ describe('Executor', function () {
it('Operations are executed in the right order', function(done) {
testRightOrder(d, done);
});


it('Works in the right order even with no supplied callback', function(done){
testExecutorWorksWithoutCallback(d, done);
});

}); // ==== End of 'With non persistent database' ====

});

0 comments on commit 41827a5

Please sign in to comment.