Skip to content

Commit 345ac2c

Browse files
committed
finishing up unit test for caolan#868 feature issue
1 parent 939a3c3 commit 345ac2c

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

mocha_test/queue.js

+33-3
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,13 @@ describe('queue', function(){
2727
it('should call the unsaturated callback if tasks length is less than concurrency minus buffer', function(done){
2828
var calls = [];
2929
var q = async.queue(function(task, cb) {
30-
// nop
31-
calls.push('process ' + task);
3230
async.setImmediate(cb);
3331
}, 10);
3432
q.unsaturated = function() {
3533
calls.push('unsaturated');
3634
};
3735
q.empty = function() {
38-
expect(calls.indexOf('unsaturated')).to.be.above(-1);
36+
expect(calls.length).to.equal(5)
3937
done();
4038
};
4139
q.push('foo0', function () {calls.push('foo0 cb');});
@@ -44,6 +42,38 @@ describe('queue', function(){
4442
q.push('foo3', function () {calls.push('foo3 cb');});
4543
q.push('foo4', function () {calls.push('foo4 cb');});
4644
});
45+
it('should call the unsaturated callback if the queue is not saturated after being saturated', function(done){
46+
var calls = [];
47+
var expectedArray = [ 'saturated',
48+
'unsaturated',
49+
'unsaturated',
50+
'unsaturated',
51+
'unsaturated',
52+
'unsaturated' ]
53+
var q = async.queue(function(task, cb) {
54+
async.setImmediate(cb);
55+
}, 1);
56+
q.unsaturated = function() {
57+
calls.push('unsaturated');
58+
};
59+
q.saturated = function() {
60+
calls.push('saturated');
61+
q.concurrency = 10;
62+
};
63+
q.empty = function() {
64+
var saturated = calls.filter(function(value){
65+
return value === 'saturated';
66+
j });
67+
expect(saturated.length).to.be.equal(1);
68+
expect(calls).to.deep.equal(expectedArray);
69+
done();
70+
};
71+
q.push('foo0', function () {calls.push('foo0 cb');});
72+
q.push('foo1', function () {calls.push('foo1 cb');});
73+
q.push('foo2', function () {calls.push('foo2 cb');});
74+
q.push('foo3', function () {calls.push('foo3 cb');});
75+
q.push('foo4', function () {calls.push('foo4 cb');});
76+
});
4777
});
4878
});
4979

0 commit comments

Comments
 (0)