mirror of
https://github.com/Studio-Saelix/sencho.git
synced 2026-08-18 22:36:19 +00:00
65f43b8032
Vitest's fork pool default scales with availableParallelism, which on machines with many cores spawns dozens of fresh workers. Each worker dynamic-imports the full Express stack (TypeScript transform + DB constructor + every migration) and saturates CPU on cold start. Most of the previous suite wall time was spent waiting on this contention rather than running tests. Cap concurrency at 4 workers via the new top-level maxWorkers / minWorkers options (Vitest 4 unified the previous poolOptions.forks.maxForks under maxWorkers across pool types). Local backend wall time drops from ~93 s to ~32-60 s on typical runs. The pre-existing pre-cap fork-contention flakes (rate limiting, metrics-routes, fleet integration) clear consistently on the warm path; the remaining variance is environmental (background processes, antivirus on Windows) and is what it was before this change minus the contention floor. testTimeout (30 s) and hookTimeout (45 s) stay generous so the stress path in database-metrics and the HTTP integration suites still cover their cold-start envelope on slow runners.
29 lines
1.2 KiB
TypeScript
29 lines
1.2 KiB
TypeScript
import { defineConfig } from 'vitest/config';
|
|
|
|
export default defineConfig({
|
|
test: {
|
|
environment: 'node',
|
|
// Only run TypeScript sources - exclude the compiled dist/ output.
|
|
include: ['src/__tests__/**/*.test.ts'],
|
|
exclude: ['dist/**', 'node_modules/**'],
|
|
// Each test file gets its own worker so singletons are fresh between files.
|
|
pool: 'forks',
|
|
// Cap concurrency: each worker dynamic-imports the full Express stack
|
|
// (TypeScript transform + DB init + every migration), so an uncapped
|
|
// fork pool that scales with availableParallelism saturates CPU and
|
|
// the suite spends most of its wall time waiting on cold-start
|
|
// contention. Four parallel workers is a sweet spot on both CI
|
|
// runners and laptops.
|
|
maxWorkers: 4,
|
|
minWorkers: 1,
|
|
// Timeout generous for DB init and HTTP calls.
|
|
testTimeout: 30_000,
|
|
// Every test file dynamic-imports the full Express stack; each fork pays
|
|
// TypeScript transformation cost and can take tens of seconds under
|
|
// CPU contention.
|
|
hookTimeout: 45_000,
|
|
// Sequential within each file (DB state is shared per file).
|
|
sequence: { concurrent: false },
|
|
},
|
|
});
|