diff --git a/test/collections/test.detect.js b/test/collections/test.detect.js index d6592ef1..cb87c1d2 100644 --- a/test/collections/test.detect.js +++ b/test/collections/test.detect.js @@ -766,6 +766,24 @@ parallel('#detectSeries', function() { }); }); + it('should not cause stack overflow', function(done) { + + var array = _.range(10000); + var calls = 0; + async.detectSeries(array, function(data, callback) { + calls++; + setImmediate(function() { + callback(null, true); + }); + }, function(err) { + if (err) { + return done(err); + } + assert.strictEqual(calls, 1); + done(); + }); + }); + }); parallel('#detectLimit', function() { @@ -1207,4 +1225,22 @@ parallel('#detectLimit', function() { }, 10 * delay); }); + it('should not cause stack overflow', function(done) { + + var array = _.range(10000); + var calls = 0; + async.detectLimit(array, 100, function(data, callback) { + calls++; + setImmediate(function() { + callback(null, true); + }); + }, function(err) { + if (err) { + return done(err); + } + assert.strictEqual(calls, 100); + done(); + }); + }); + });