summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolan McMahon <caolan@caolanmcmahon.com>2014-03-28 14:42:14 +0000
committerCaolan McMahon <caolan@caolanmcmahon.com>2014-03-28 14:42:46 +0000
commit95fec40c0c64ff221611e07bc59230314c3da665 (patch)
tree5dd713aa2b24b16f8def4223124f3cb213347ada
parentf5c518eb65a3b97eebef1461b168db17372c1b87 (diff)
downloadasync-95fec40c0c64ff221611e07bc59230314c3da665.tar.gz
use domains to stop error bubbling in #420 test
-rwxr-xr-xtest/test-async.js42
1 files changed, 29 insertions, 13 deletions
diff --git a/test/test-async.js b/test/test-async.js
index 0948672..3d62bf8 100755
--- a/test/test-async.js
+++ b/test/test-async.js
@@ -433,22 +433,38 @@ exports['auto removeListener has side effect on loop iterator'] = function(test)
// Issue 410 on github: https://github.com/caolan/async/issues/410
exports['auto calls callback multiple times'] = function(test) {
+ if (typeof process === 'undefined') {
+ // node only test
+ return;
+ }
var finalCallCount = 0;
- async.auto({
- task1: function(callback) { callback(null); },
- task2: ['task1', function(callback) { callback(null); }]
- },
-
- // Error throwing final callback. This should only run once
- function(err) {
- finalCallCount++;
- if (finalCallCount > 1) {
- test.done(new Error("Final auto callback should only be called once"));
- } else {
- test.done();
- throw new Error("An error");
+ 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(err) {
+ 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['waterfall'] = function(test){