Skip to content

Commit a0f8cbc

Browse files
committed
test(fmt): simplify bounded scheduling coverage
1 parent 956002b commit a0f8cbc

1 file changed

Lines changed: 13 additions & 41 deletions

File tree

‎packages/rstack/tests/fmt/runnerScheduling.test.ts‎

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,60 +6,32 @@ import type { FmtFileRequest } from '../../src/fmt/types.ts';
66
const state = rs.hoisted(() => ({
77
active: 0,
88
peak: 0,
9-
started: [] as string[],
9+
completed: [] as string[],
1010
}));
1111

1212
rs.mock('../../src/fmt/workerPool.ts', () => ({
1313
createWorkerPool: (_fileCount: number, workerCount: number) => ({
1414
workerCount,
1515
async formatFile(file: FmtFileRequest) {
16-
state.started.push(file.path);
1716
state.peak = Math.max(state.peak, ++state.active);
1817
await setImmediate();
19-
// Finish out of order and fail one file without stopping the queue.
20-
if (file.path === '0.ts') {
21-
await setImmediate();
22-
}
2318
state.active--;
24-
if (file.path === '1.ts') {
25-
throw new Error('format failed');
26-
}
27-
return { status: 'changed' };
19+
state.completed.push(file.path);
20+
return { status: 'unchanged' };
2821
},
2922
terminate: () => Promise.resolve(),
3023
}),
3124
}));
3225

33-
test.each([2, 8])(
34-
'bounds scheduling to %i workers and preserves result order after failures',
35-
async (maxWorkers) => {
36-
state.active = 0;
37-
state.peak = 0;
38-
state.started = [];
39-
const paths = Array.from({ length: 20 }, (_, index) =>
40-
index === 10 ? '10.md' : index === 15 ? '15.mdx' : `${index}.ts`,
41-
);
26+
test('bounds in-flight tasks and processes every file', async () => {
27+
const paths = Array.from({ length: 6 }, (_, index) => `${index}.ts`);
4228

43-
const result = await runFmtFiles({
44-
files: paths.map((path) => ({ path, options: {} })),
45-
mode: 'check',
46-
maxWorkers,
47-
});
29+
await runFmtFiles({
30+
files: paths.map((path) => ({ path, options: {} })),
31+
mode: 'check',
32+
maxWorkers: 2,
33+
});
4834

49-
expect(state.peak).toBe(maxWorkers);
50-
expect(state.started).toEqual(
51-
maxWorkers === 8
52-
? ['10.md', '15.mdx', ...paths.filter((path) => path.endsWith('.ts'))]
53-
: paths,
54-
);
55-
expect(result).toEqual({
56-
exitCode: 2,
57-
processedFileCount: paths.length,
58-
files: paths.map((path) =>
59-
path === '1.ts'
60-
? { path, status: 'error', error: new Error('format failed') }
61-
: { path, status: 'different' },
62-
),
63-
});
64-
},
65-
);
35+
expect(state.peak).toBe(2);
36+
expect(state.completed.sort()).toEqual(paths);
37+
});

0 commit comments

Comments
 (0)