diff options
author | Steve Robb <softnfuzzyrobb@gmail.com> | 2016-03-06 16:46:12 +0000 |
---|---|---|
committer | Steve Robb <softnfuzzyrobb@gmail.com> | 2016-03-06 16:46:12 +0000 |
commit | 828231b16f339dbeaf4559ea692a592cc4566f50 (patch) | |
tree | 0fd845e8004e2dd3b7e6f5dcbe6f86d5ddccd0cc | |
parent | 99920c3f73be88a66046ec953ee896d1506c72e6 (diff) | |
download | async-828231b16f339dbeaf4559ea692a592cc4566f50.tar.gz |
autoInject tests updated.
-rwxr-xr-x | test/test-async.js | 238 |
1 files changed, 168 insertions, 70 deletions
diff --git a/test/test-async.js b/test/test-async.js index 8133a1c..3253336 100755 --- a/test/test-async.js +++ b/test/test-async.js @@ -487,9 +487,138 @@ exports['auto error should pass partial results'] = function(test) { }); }; +// Issue 24 on github: https://github.com/caolan/async/issues#issue/24 +// Issue 76 on github: https://github.com/caolan/async/issues#issue/76 +exports['auto removeListener has side effect on loop iterator'] = function(test) { + async.auto({ + task1: ['task3', function(/*callback*/) { test.done(); }], + task2: ['task3', function(/*callback*/) { /* by design: DON'T call callback */ }], + task3: function(callback) { callback(); } + }); +}; + +// Issue 410 on github: https://github.com/caolan/async/issues/410 +exports['auto calls callback multiple times'] = function(test) { + if (isBrowser()) { + // node only test + test.done(); + return; + } + var finalCallCount = 0; + var domain = require('domain').create(); + domain.on('error', function (e) { + // ignore test error + if (!e._test_error) { + return test.done(e); + } + }); + domain.run(function () { + async.auto({ + task1: function(callback) { callback(null); }, + task2: ['task1', function(callback) { callback(null); }] + }, + + // Error throwing final callback. This should only run once + function() { + finalCallCount++; + var e = new Error("An error"); + e._test_error = true; + throw e; + }); + }); + setTimeout(function () { + test.equal(finalCallCount, 1, + "Final auto callback should only be called once" + ); + test.done(); + }, 10); +}; + + +exports['auto calls callback multiple times with parallel functions'] = function(test) { + test.expect(1); + async.auto({ + task1: function(callback) { setTimeout(callback,0,"err"); }, + task2: function(callback) { setTimeout(callback,0,"err"); } + }, + // Error throwing final callback. This should only run once + function(err) { + test.equal(err, "err"); + test.done(); + }); +}; + + +// Issue 462 on github: https://github.com/caolan/async/issues/462 +exports['auto modifying results causes final callback to run early'] = function(test) { + async.auto({ + task1: function(callback, results){ + results.inserted = true; + callback(null, 'task1'); + }, + task2: function(callback){ + setTimeout(function(){ + callback(null, 'task2'); + }, 50); + }, + task3: function(callback){ + setTimeout(function(){ + callback(null, 'task3'); + }, 100); + } + }, + function(err, results){ + test.equal(results.inserted, true); + test.ok(results.task3, 'task3'); + test.done(); + }); +}; + +// Issue 263 on github: https://github.com/caolan/async/issues/263 +exports['auto prevent dead-locks due to inexistant dependencies'] = function(test) { + test.throws(function () { + async.auto({ + task1: ['noexist', function(callback){ + callback(null, 'task1'); + }] + }); + }, Error); + test.done(); +}; + +// Issue 263 on github: https://github.com/caolan/async/issues/263 +exports['auto prevent dead-locks due to cyclic dependencies'] = function(test) { + test.throws(function () { + async.auto({ + task1: ['task2', function(callback){ + callback(null, 'task1'); + }], + task2: ['task1', function(callback){ + callback(null, 'task2'); + }] + }); + }, Error); + test.done(); +}; + +// Issue 988 on github: https://github.com/caolan/async/issues/988 +exports['auto stops running tasks on error'] = function(test) { + async.auto({ + task1: function (callback) { + callback('error'); + }, + task2: function (callback) { + test.ok(false, 'test2 should not be called'); + callback(); + } + }, 1, function (error) { + test.equal(error, 'error', 'finishes with error'); + test.done(); + }); +}; + exports['autoInject'] = function(test){ var callOrder = []; - var testdata = [{test: 'test'}]; async.autoInject({ task1: function(task2, callback){ setTimeout(function(){ @@ -513,8 +642,8 @@ exports['autoInject'] = function(test){ }, task5: function(task2, callback){ setTimeout(function(){ - callOrder.push('task5'); - callback(); + callOrder.push('task5'); + callback(); }, 0); }, task6: function(task2, callback){ @@ -523,6 +652,7 @@ exports['autoInject'] = function(test){ } }, function(err){ + test.ok(err === null, err + " passed instead of 'null'"); test.same(callOrder, ['task2','task6','task3','task5','task1','task4']); test.done(); }); @@ -553,6 +683,7 @@ exports['autoInject petrify'] = function (test) { } }, function (err) { + if (err) throw err; test.same(callOrder, ['task2', 'task3', 'task1', 'task4']); test.done(); }); @@ -561,43 +692,44 @@ exports['autoInject petrify'] = function (test) { exports['autoInject results'] = function(test){ var callOrder = []; async.autoInject({ - task1: function(task2, callback){ + task1: function(task2, callback){ test.same(task2, 'task2'); setTimeout(function(){ callOrder.push('task1'); callback(null, 'task1a', 'task1b'); }, 25); }, - task2: function(callback){ + task2: function(callback){ setTimeout(function(){ callOrder.push('task2'); callback(null, 'task2'); }, 50); }, - task3: function(task2, callback){ + task3: function(task2, callback){ test.same(task2, 'task2'); callOrder.push('task3'); callback(null); }, - task4: function(task1, task2, callback){ + task4: function(task1, task2, callback){ test.same(task1, ['task1a','task1b']); test.same(task2, 'task2'); callOrder.push('task4'); callback(null, 'task4'); } }, - function(err, task2, task4, task3, task1){ + function(err, task1, task2, task3, task4){ test.same(callOrder, ['task2','task3','task1','task4']); test.same(task1, ['task1a','task1b']); test.same(task2, 'task2'); - test.same(task3, undefined); - test.same(task4, 'task4'); + test.same(task3, undefined); + test.same(task4, 'task4'); test.done(); }); }; exports['autoInject empty object'] = function(test){ async.autoInject({}, function(err){ + test.ok(err === null, err + " passed instead of 'null'"); test.done(); }); }; @@ -629,6 +761,13 @@ exports['autoInject no callback'] = function(test){ }); }; +exports['autoInject concurrency no callback'] = function(test){ + async.autoInject({ + task1: function(callback){callback();}, + task2: function(task1, callback){callback(); test.done();} + }, 1); +}; + exports['autoInject error should pass partial results'] = function(test) { async.autoInject({ task1: function(callback){ @@ -651,16 +790,16 @@ exports['autoInject error should pass partial results'] = function(test) { // Issue 24 on github: https://github.com/caolan/async/issues#issue/24 // Issue 76 on github: https://github.com/caolan/async/issues#issue/76 -exports['auto removeListener has side effect on loop iterator'] = function(test) { - async.auto({ - task1: ['task3', function(/*callback*/) { test.done(); }], - task2: ['task3', function(/*callback*/) { /* by design: DON'T call callback */ }], +exports['autoInject removeListener has side effect on loop iterator'] = function(test) { + async.autoInject({ + task1: function(task3, callback) { test.done(); }, + task2: function(task3, callback) { /* by design: DON'T call callback */ }, task3: function(callback) { callback(); } }); }; // Issue 410 on github: https://github.com/caolan/async/issues/410 -exports['auto calls callback multiple times'] = function(test) { +exports['autoInject calls callback multiple times'] = function(test) { if (isBrowser()) { // node only test test.done(); @@ -675,9 +814,9 @@ exports['auto calls callback multiple times'] = function(test) { } }); domain.run(function () { - async.auto({ + async.autoInject({ task1: function(callback) { callback(null); }, - task2: ['task1', function(callback) { callback(null); }] + task2: function(task1, callback) { callback(null); } }, // Error throwing final callback. This should only run once @@ -697,9 +836,9 @@ exports['auto calls callback multiple times'] = function(test) { }; -exports['auto calls callback multiple times with parallel functions'] = function(test) { +exports['autoInject calls callback multiple times with parallel functions'] = function(test) { test.expect(1); - async.auto({ + async.autoInject({ task1: function(callback) { setTimeout(callback,0,"err"); }, task2: function(callback) { setTimeout(callback,0,"err"); } }, @@ -711,74 +850,33 @@ exports['auto calls callback multiple times with parallel functions'] = function }; -// Issue 462 on github: https://github.com/caolan/async/issues/462 -exports['auto modifying results causes final callback to run early'] = function(test) { - async.auto({ - task1: function(callback, results){ - results.inserted = true; - callback(null, 'task1'); - }, - task2: function(callback){ - setTimeout(function(){ - callback(null, 'task2'); - }, 50); - }, - task3: function(callback){ - setTimeout(function(){ - callback(null, 'task3'); - }, 100); - } - }, - function(err, results){ - test.equal(results.inserted, true); - test.ok(results.task3, 'task3'); - test.done(); - }); -}; - // Issue 263 on github: https://github.com/caolan/async/issues/263 -exports['auto prevent dead-locks due to inexistant dependencies'] = function(test) { +exports['autoInject prevent dead-locks due to inexistant dependencies'] = function(test) { test.throws(function () { - async.auto({ - task1: ['noexist', function(callback){ + async.autoInject({ + task1: function(noexist, callback){ callback(null, 'task1'); - }] + } }); }, Error); test.done(); }; // Issue 263 on github: https://github.com/caolan/async/issues/263 -exports['auto prevent dead-locks due to cyclic dependencies'] = function(test) { +exports['autoInject prevent dead-locks due to cyclic dependencies'] = function(test) { test.throws(function () { - async.auto({ - task1: ['task2', function(callback){ + async.autoInject({ + task1: function(task2, callback){ callback(null, 'task1'); - }], - task2: ['task1', function(callback){ + }, + task2: function(task1, callback){ callback(null, 'task2'); - }] + } }); }, Error); test.done(); }; -// Issue 988 on github: https://github.com/caolan/async/issues/988 -exports['auto stops running tasks on error'] = function(test) { - async.auto({ - task1: function (callback) { - callback('error'); - }, - task2: function (callback) { - test.ok(false, 'test2 should not be called'); - callback(); - } - }, 1, function (error) { - test.equal(error, 'error', 'finishes with error'); - test.done(); - }); -}; - // Issue 306 on github: https://github.com/caolan/async/issues/306 exports['retry when attempt succeeds'] = function(test) { var failed = 3; |