|
| 1 | +var async = require('../lib'); |
| 2 | +var expect = require('chai').expect; |
| 3 | + |
| 4 | + |
| 5 | +describe('queue', function(){ |
| 6 | + context('q.unsaturated(): ',function() { |
| 7 | + it('should have a default buffer property that equals 25% of the concurrenct rate', function(done){ |
| 8 | + var q = async.queue(function(task, cb) { |
| 9 | + // nop |
| 10 | + calls.push('process ' + task); |
| 11 | + async.setImmediate(cb); |
| 12 | + }, 10); |
| 13 | + expect(q.buffer).to.equal(2.5); |
| 14 | + done(); |
| 15 | + }); |
| 16 | + it('should allow a user to change the buffer property', function(done){ |
| 17 | + var q = async.queue(function(task, cb) { |
| 18 | + // nop |
| 19 | + calls.push('process ' + task); |
| 20 | + async.setImmediate(cb); |
| 21 | + }, 10); |
| 22 | + q.buffer = 4; |
| 23 | + expect(q.buffer).to.not.equal(2.5); |
| 24 | + expect(q.buffer).to.equal(4); |
| 25 | + done(); |
| 26 | + }); |
| 27 | + it('should call the unsaturated callback if tasks length is less than concurrency minus buffer', function(done){ |
| 28 | + var calls = []; |
| 29 | + var q = async.queue(function(task, cb) { |
| 30 | + // nop |
| 31 | + calls.push('process ' + task); |
| 32 | + async.setImmediate(cb); |
| 33 | + }, 10); |
| 34 | + q.unsaturated = function() { |
| 35 | + calls.push('unsaturated'); |
| 36 | + }; |
| 37 | + q.empty = function() { |
| 38 | + expect(calls.indexOf('unsaturated')).to.be.above(-1); |
| 39 | + done(); |
| 40 | + }; |
| 41 | + q.push('foo0', function () {calls.push('foo0 cb');}); |
| 42 | + q.push('foo1', function () {calls.push('foo1 cb');}); |
| 43 | + q.push('foo2', function () {calls.push('foo2 cb');}); |
| 44 | + q.push('foo3', function () {calls.push('foo3 cb');}); |
| 45 | + q.push('foo4', function () {calls.push('foo4 cb');}); |
| 46 | + }); |
| 47 | + }); |
| 48 | +}); |
| 49 | + |
0 commit comments