summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohan Nordberg <its@johan-nordberg.com>2016-05-29 12:07:32 +0200
committerJohan Nordberg <its@johan-nordberg.com>2016-05-29 12:07:32 +0200
commit6037f03e2a6ce9f6b8f02eb4842c37cf0a10b34d (patch)
treece6645aed3a8e5e0721eb85a4baabf56c1221ec5
parent0e56ab5c60012d86306f814394fa22ec4252b367 (diff)
downloadasync-6037f03e2a6ce9f6b8f02eb4842c37cf0a10b34d.tar.gz
Add tests for queue error handler
-rw-r--r--mocha_test/queue.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/mocha_test/queue.js b/mocha_test/queue.js
index de21ef4..8ba5770 100644
--- a/mocha_test/queue.js
+++ b/mocha_test/queue.js
@@ -155,6 +155,33 @@ describe('queue', function(){
});
});
+ it('global error handler', function(done){
+ var results = [];
+
+ var q = async.queue(function (task, callback) {
+ callback(task.name === 'foo' ? new Error('fooError') : null);
+ }, 2);
+
+ q.error = function(error, task) {
+ expect(error).to.exist;
+ expect(error.message).to.equal('fooError');
+ expect(task.name).to.equal('foo');
+ results.push('fooError');
+ };
+
+ q.drain = function() {
+ expect(results).to.eql(['fooError', 'bar']);
+ done();
+ };
+
+ q.push({name: 'foo'});
+
+ q.push({name: 'bar'}, function(error) {
+ expect(error).to.not.exist;
+ results.push('bar');
+ });
+ });
+
// The original queue implementation allowed the concurrency to be changed only
// on the same event loop during which a task was added to the queue. This
// test attempts to be a more robust test.