From 07cb01a21558a0b15745de13db1b8f249ab797a0 Mon Sep 17 00:00:00 2001 From: Suguru Motegi Date: Sun, 16 Oct 2016 16:00:03 -0700 Subject: [PATCH] test(detect): add test https://github.com/caolan/async/issues/1293 --- test/collections/test.detect.js | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) 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(); + }); + }); + });