summaryrefslogtreecommitdiff
path: root/test/test-async.js
diff options
context:
space:
mode:
authorCorey Jewett <cj@syntheticplayground.com>2012-11-18 00:51:35 -0800
committerCorey Jewett <cj@syntheticplayground.com>2012-11-18 00:51:35 -0800
commitbb43829d29e91c8f314704876293ae3f7b22c82d (patch)
tree9fcc70a37832a53638aa558a0a6640968e2b8c7a /test/test-async.js
parent96a7da519adc9e8cb3c187a2da4945f5edea71d3 (diff)
downloadasync-bb43829d29e91c8f314704876293ae3f7b22c82d.tar.gz
In #forEach and queue's worker calling the callback more than once causes bad behavior. Throw an Error when this happens.
Diffstat (limited to 'test/test-async.js')
-rw-r--r--test/test-async.js28
1 files changed, 26 insertions, 2 deletions
diff --git a/test/test-async.js b/test/test-async.js
index 39ec47d..9880f94 100644
--- a/test/test-async.js
+++ b/test/test-async.js
@@ -533,6 +533,18 @@ exports['forEach'] = function(test){
});
};
+exports['forEach extra callback'] = function(test){
+ var count = 0;
+ async.forEach([1,3,2], function(val, callback) {
+ count++;
+ callback();
+ test.throws(callback);
+ if (count == 3) {
+ test.done();
+ }
+ });
+};
+
exports['forEach empty array'] = function(test){
test.expect(1);
async.forEach([], function(x, callback){
@@ -1284,7 +1296,7 @@ exports['queue'] = function (test) {
test.equal(q.length(), 4);
test.equal(q.concurrency, 2);
- setTimeout(function () {
+ q.drain = function () {
test.same(call_order, [
'process 2', 'callback 2',
'process 1', 'callback 1',
@@ -1294,7 +1306,7 @@ exports['queue'] = function (test) {
test.equal(q.concurrency, 2);
test.equal(q.length(), 0);
test.done();
- }, 800);
+ };
};
exports['queue changing concurrency'] = function (test) {
@@ -1383,6 +1395,18 @@ exports['queue push without callback'] = function (test) {
}, 800);
};
+exports['queue too many callbacks'] = function (test) {
+ var q = async.queue(function (task, callback) {
+ callback();
+ test.throws(function() {
+ callback();
+ });
+ test.done();
+ }, 2);
+
+ q.push(1);
+};
+
exports['queue bulk task'] = function (test) {
var call_order = [],
delays = [160,80,240,80];