Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion stryker.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
};
27 changes: 27 additions & 0 deletions test/parsePdf.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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}`,
);
});
});
});