Skip to content

Commit

Permalink
test(cursor): repro #8235
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Oct 19, 2019
1 parent 875d681 commit ba18b9d
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/helpers/cursor.eachAsync.test.js
@@ -0,0 +1,30 @@
'use strict';

const assert = require('assert');
const eachAsync = require('../../lib/helpers/cursor/eachAsync');

describe('eachAsync()', function() {
it('exhausts large cursor without parallel calls (gh-8235)', function() {
this.timeout(10000);

let numInProgress = 0;
let num = 0;
const max = 1000;
let processed = 0;

function next(cb) {
assert.equal(numInProgress, 0);
++numInProgress;
setTimeout(function() {
--numInProgress;
if (num++ >= max) {
return cb(null, null);
}
cb(null, { name: `doc${num}` });
}, 0);
}

return eachAsync(next, () => Promise.resolve(++processed), { parallel: 8 }).
then(() => assert.equal(processed, max));
});
});

0 comments on commit ba18b9d

Please sign in to comment.