Skip to content

Commit

Permalink
tests: create better test for Pool.run() asynchronocity; refactor mai…
Browse files Browse the repository at this point in the history
…n code slightly, same behavior, tests pass.
  • Loading branch information
DrPaulBrewer committed May 24, 2016
1 parent 3e38c97 commit ac26fdf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,10 @@ Pool.prototype.run = function(untilTime, done, batch){
return (nextAgent && (nextAgent.wakeTime < untilTime));
},
function(cb){
async.setImmediate(function(){ that.syncRun(untilTime, batch || 1); cb(false); });
async.setImmediate(function(){
that.syncRun(untilTime, batch || 1);
cb();
});
},
function(e,d){
done.call(that,e);
Expand Down
2 changes: 2 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,8 @@ describe('new Pool', function(){
done();
};
myPool.run(1000, cb, 53);
/* previous line should return immediately, before event loop runs, so wakeCounts are zero */
wakes.forEach(function(wakeCount, i){ wakeCount.should.equal(0); });
} else {
myPool.syncRun(1000);
checkWakes();
Expand Down

0 comments on commit ac26fdf

Please sign in to comment.