diff options
author | Ernie Casilla <ecasilla@icloud.com> | 2016-02-19 20:48:46 -0500 |
---|---|---|
committer | Ernie Casilla <ecasilla@icloud.com> | 2016-02-20 09:14:35 -0500 |
commit | e6421579841cf78da5e19c9a7964e1e4f8dcb153 (patch) | |
tree | 8fc1240ebecd9832179f402645efd852d462225b /mocha_test | |
parent | 5da468f5951f66fb97b4defe86fbe667fb51a92f (diff) | |
download | async-e6421579841cf78da5e19c9a7964e1e4f8dcb153.tar.gz |
added a base implementation for unsaturation event #868
updating the README
fix readme
Diffstat (limited to 'mocha_test')
-rw-r--r-- | mocha_test/queue.js | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/mocha_test/queue.js b/mocha_test/queue.js new file mode 100644 index 0000000..fab423a --- /dev/null +++ b/mocha_test/queue.js @@ -0,0 +1,49 @@ +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 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 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) { + // nop + 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); + done(); + }; + 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');}); + }); + }); +}); + |