Skip to content

Commit

Permalink
fix queue test
Browse files Browse the repository at this point in the history
  • Loading branch information
suguru03 committed Feb 24, 2016
1 parent 3d1781c commit 0ab9c9b
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions mocha_test/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var expect = require('chai').expect;
describe('queue', function(){
context('q.unsaturated(): ',function() {
it('should have a default buffer property that equals 25% of the concurrenct rate', function(done){
var calls = [];
var q = async.queue(function(task, cb) {
// nop
calls.push('process ' + task);
Expand All @@ -14,6 +15,7 @@ describe('queue', function(){
done();
});
it('should allow a user to change the buffer property', function(done){
var calls = [];
var q = async.queue(function(task, cb) {
// nop
calls.push('process ' + task);
Expand All @@ -27,7 +29,6 @@ describe('queue', function(){
it('should call the unsaturated callback if tasks length is less than concurrency minus buffer', function(done){
var calls = [];
var q = async.queue(function(task, cb) {
// nop
calls.push('process ' + task);
async.setImmediate(cb);
}, 10);
Expand All @@ -36,7 +37,26 @@ describe('queue', function(){
};
q.empty = function() {
expect(calls.indexOf('unsaturated')).to.be.above(-1);
done();
setTimeout(function() {
expect(calls).eql([
'unsaturated',
'unsaturated',
'unsaturated',
'unsaturated',
'unsaturated',
'process foo0',
'process foo1',
'process foo2',
'process foo3',
'process foo4',
'foo0 cb',
'foo1 cb',
'foo2 cb',
'foo3 cb',
'foo4 cb'
]);
done();
}, 50);
};
q.push('foo0', function () {calls.push('foo0 cb');});
q.push('foo1', function () {calls.push('foo1 cb');});
Expand Down

0 comments on commit 0ab9c9b

Please sign in to comment.