Skip to content

Commit

Permalink
test: make parallelLimit test more robust to timing issues
Browse files Browse the repository at this point in the history
Fix #8386
  • Loading branch information
vkarpov15 committed Dec 6, 2019
1 parent faabdbb commit 6ec6980
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions test/parallelLimit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,36 @@ describe('parallelLimit', function() {
});

it('executes functions in parallel', function(done) {
let called = 0;
let started = 0;
let finished = 0;
const fns = [
cb => {
++started;
setTimeout(() => {
++called;
++finished;
setTimeout(cb, 0);
}, 100);
},
cb => {
++started;
setTimeout(() => {
++called;
++finished;
setTimeout(cb, 0);
}, 100);
},
cb => {
assert.equal(called, 2);
++called;
setTimeout(cb, 100);
assert.equal(started, 2);
assert.ok(finished > 0);
++started;
++finished;
setTimeout(cb, 0);
}
];

parallelLimit(fns, 2, (err) => {
assert.ifError(err);
assert.equal(called, 3);
assert.equal(started, 3);
assert.equal(finished, 3);
done();
});
});
Expand Down

0 comments on commit 6ec6980

Please sign in to comment.