fix(test): do not force eight int workers on CI

An explicit maxWorkers: 8 raised parallelism on 2–4 vCPU runners and
starved shared invite/consent advisory leases (15s timeouts). Cap only
on local high-core hosts; leave CI on Vitest's CPU-relative default.
This commit is contained in:
Francisco Solla 2026-08-05 21:06:04 -03:00
parent 1a3084a6ee
commit 13f9940f53

View file

@ -1,9 +1,20 @@
import os from 'node:os'
import path from 'node:path' import path from 'node:path'
import react from '@vitejs/plugin-react' import react from '@vitejs/plugin-react'
import tsconfigPaths from 'vite-tsconfig-paths' import tsconfigPaths from 'vite-tsconfig-paths'
import { defineConfig } from 'vitest/config' import { defineConfig } from 'vitest/config'
// Cap forks on high-core local machines so Payload pools stay under Docker
// Postgres max_connections (default worker count ≈ CPUs; 16× pool-max-10 ≈
// 160 clients → "too many clients already"). Do NOT set a literal
// `maxWorkers: 8` on CI: Vitest treats that as "use up to 8" even on 2–4
// vCPU runners, which starves shared advisory leases (invite/consent) and
// times out at 15s. Leave CI on Vitest's CPU-relative default.
const maxWorkers = process.env.CI
? undefined
: Math.min(8, os.availableParallelism())
export default defineConfig({ export default defineConfig({
resolve: { resolve: {
alias: { alias: {
@ -15,11 +26,7 @@ export default defineConfig({
environment: 'jsdom', environment: 'jsdom',
setupFiles: ['./vitest.setup.ts'], setupFiles: ['./vitest.setup.ts'],
include: ['tests/int/**/*.int.spec.ts'], include: ['tests/int/**/*.int.spec.ts'],
// Cap forks so each worker's Payload pg pool stays under Docker Postgres ...(maxWorkers === undefined ? {} : { maxWorkers }),
// max_connections=100 on high-core laptops (default worker count ≈ CPUs;
// 16× pool-max-10 ≈ 160 clients → "too many clients already", which then
// cascades into unrelated QueryError noise). CI runners have fewer CPUs.
maxWorkers: 8,
// Int specs hit a real Postgres under a parallel suite, so wall time is // Int specs hit a real Postgres under a parallel suite, so wall time is
// dominated by pool contention, not by the code under test. The 5s // dominated by pool contention, not by the code under test. The 5s
// default made legitimately heavy RSC-composition tests flake as the // default made legitimately heavy RSC-composition tests flake as the