Skip to content

Commit

Permalink
test(cursor): repro #8352
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Dec 4, 2019
1 parent 491b9cc commit d4a7ef3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
File renamed without changes.
32 changes: 32 additions & 0 deletions test/helpers/cursor.eachAsync.test.js
Expand Up @@ -27,4 +27,36 @@ describe('eachAsync()', function() {
return eachAsync(next, () => Promise.resolve(++processed), { parallel: 8 }).
then(() => assert.equal(processed, max));
});

it('waits until the end before resolving the promise (gh-8352)', function() {
const max = 2;
let numCalled = 0;
let numDone = 0;
function next(cb) {
setImmediate(() => {
if (++numCalled > max) {
return cb(null, null);
}
cb(null, { num: numCalled });
});
}

function fn() {
return new Promise(resolve => {
setTimeout(() => {
++numDone;
resolve();
}, 100);
});
}

return eachAsync(next, fn, { parallel: 3 }).
then(() => assert.equal(numDone, max)).
then(() => {
numCalled = 0;
numDone = 0;
}).
then(() => eachAsync(next, fn, { parallel: 2 })).
then(() => assert.equal(numDone, max));
});
});
3 changes: 2 additions & 1 deletion test/mocha.opts
@@ -1,2 +1,3 @@
--reporter dot
--ui bdd
--ui bdd
--recursive

0 comments on commit d4a7ef3

Please sign in to comment.