diff options
Diffstat (limited to 'mocha_test/priorityQueue.js')
-rw-r--r-- | mocha_test/priorityQueue.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/mocha_test/priorityQueue.js b/mocha_test/priorityQueue.js index b777815..f71e665 100644 --- a/mocha_test/priorityQueue.js +++ b/mocha_test/priorityQueue.js @@ -108,6 +108,35 @@ describe('priorityQueue', function() { }; }); + it('pause in worker with concurrency', function(done) { + var call_order = []; + var q = async.priorityQueue(function (task, callback) { + if (task.isLongRunning) { + q.pause(); + setTimeout(function () { + call_order.push(task.id); + q.resume(); + callback(); + }, 50); + } + else { + call_order.push(task.id); + setTimeout(callback, 10); + } + }, 10); + + q.push({ id: 1, isLongRunning: true}); + q.push({ id: 2 }); + q.push({ id: 3 }); + q.push({ id: 4 }); + q.push({ id: 5 }); + + q.drain = function () { + expect(call_order).to.eql([1, 2, 3, 4, 5]); + done(); + }; + }); + context('q.saturated(): ', function() { it('should call the saturated callback if tasks length is concurrency', function(done) { var calls = []; |