diff --git a/stryker.config.mjs b/stryker.config.mjs index fe14adc..4077997 100644 --- a/stryker.config.mjs +++ b/stryker.config.mjs @@ -52,5 +52,6 @@ export default { reporters: ['html', 'clear-text', 'progress', 'json'], htmlReporter: { fileName: 'reports/mutation/index.html' }, jsonReporter: { fileName: 'reports/mutation/mutation.json' }, - thresholds: { break: null, high: 80, low: 60 }, + // `break` fails the run below this score. Raise it as mutants get killed. + thresholds: { break: 60, high: 80, low: 60 }, }; diff --git a/test/parsePdf.test.ts b/test/parsePdf.test.ts index 702ff6d..b942e0e 100644 --- a/test/parsePdf.test.ts +++ b/test/parsePdf.test.ts @@ -2,6 +2,7 @@ import assert from 'node:assert'; import { readFile } from 'node:fs/promises'; import path from 'node:path'; import { describe, it } from 'node:test'; +import { setTimeout as delay } from 'node:timers/promises'; import { parsePdf } from '#afpp/src/index.js'; @@ -126,4 +127,30 @@ describe('parsePdf', () => { assert.equal(data.length, 9); }); }); + + describe('concurrency limit', () => { + it('should run at most `concurrency` pages at the same time', async () => { + const input = path.join('test', 'example.pdf'); + const concurrency = 2; + let active = 0; + let peak = 0; + + const data = await parsePdf(input, { concurrency }, async (content) => { + active++; + peak = Math.max(peak, active); + // Hold the slot so that pages processed at the same time overlap here. + await delay(50); + active--; + return content; + }); + + assert.equal(data.length, 9); + // Without the limit all nine pages start at once and the peak is 9. + assert.equal( + peak, + concurrency, + `expected at most ${concurrency} pages at a time, saw ${peak}`, + ); + }); + }); });