diff options
author | Hubert Argasinski <argasinski.hubert@gmail.com> | 2017-06-21 23:07:18 -0400 |
---|---|---|
committer | Hubert Argasinski <argasinski.hubert@gmail.com> | 2017-06-21 23:07:18 -0400 |
commit | a0ffde83e42ae407514faaa8e754912d91df713f (patch) | |
tree | 41cc14d34e5c528a614bfcb59a9021d6eb5922e6 /mocha_test | |
parent | 39b20e6da268b2b737df7b068d32620b59011474 (diff) | |
download | async-concat-order.tar.gz |
PR fixesconcat-order
Diffstat (limited to 'mocha_test')
-rw-r--r-- | mocha_test/concat.js | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/mocha_test/concat.js b/mocha_test/concat.js index f84a84b..f6b73b3 100644 --- a/mocha_test/concat.js +++ b/mocha_test/concat.js @@ -307,9 +307,9 @@ describe('concat', function() { it('does not continue replenishing after error', function(done) { var started = 0; var arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; - var delay = 10; var limit = 3; - var maxTime = 10 * arr.length; + var step = 0; + var maxSteps = arr.length; async.concatLimit(arr, limit, function(val, next) { started++; @@ -317,18 +317,28 @@ describe('concat', function() { return next(new Error('fail')); } - setTimeout(function() { + async.setImmediate(function() { next(); - }, delay); + }); }, function(err, result) { expect(err).to.not.eql(null); expect(result).to.be.an('array').that.is.empty; }); - setTimeout(function() { - expect(started).to.equal(3); - done(); - }, maxTime); + // wait `maxSteps` event loop cycles before calling done to ensure + // the iteratee is not called on more items in arr. + function waitCycle() { + step++; + if (step >= maxSteps) { + expect(started).to.equal(3); + done(); + return; + } else { + async.setImmediate(waitCycle); + } + } + + async.setImmediate(waitCycle); }); }); |