1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
var async = require('../lib');
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);
async.setImmediate(cb);
}, 10);
expect(q.buffer).to.equal(2.5);
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);
async.setImmediate(cb);
}, 10);
q.buffer = 4;
expect(q.buffer).to.not.equal(2.5);
expect(q.buffer).to.equal(4);
done();
});
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) {
calls.push('process ' + task);
async.setImmediate(cb);
}, 10);
q.unsaturated = function() {
calls.push('unsaturated');
};
q.empty = function() {
expect(calls.indexOf('unsaturated')).to.be.above(-1);
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');});
q.push('foo2', function () {calls.push('foo2 cb');});
q.push('foo3', function () {calls.push('foo3 cb');});
q.push('foo4', function () {calls.push('foo4 cb');});
});
});
});
|