diff --git a/test/helpers/cursor.eachAsync.test.js b/test/helpers/cursor.eachAsync.test.js new file mode 100644 index 00000000000..f64ea2ffe27 --- /dev/null +++ b/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)); + }); +}); \ No newline at end of file