fix(e2e): size the Playwright pool by the container's CPU quota
CI / gates (pull_request) Successful in 54s
Reusable / Security / Secrets (gitleaks) (pull_request) Successful in 15s
Reusable / Security / Rust (cargo-deny) (pull_request) Skipped
Reusable / Security / .NET (NuGetAudit) (pull_request) Skipped
Reusable / Security / SAST (Opengrep) (pull_request) Successful in 33s
Reusable / Security / Dependencies (osv-scanner) (pull_request) Successful in 19s
Security / security (pull_request) Successful in 1m8s
Reusable / Qodana / Qodana (pull_request) Successful in 3m8s
CI / build (pull_request) Successful in 4m44s
Qodana / qodana (pull_request) Successful in 3m8s
CI / record (pull_request) Skipped
CI / deploy (pull_request) Skipped

The ubuntu jobs moved to the runner `anon-docker` on 2026-12-04, whose job
containers run with `--cpus=4`. os.cpus() still reports the host's 28
cores, so Playwright started 14 workers on four CPUs: axe on /apps went from
~9 s to over 30 s and the a11y tests timed out — on main too (dispatched
run 1565), so not a dependency regression.

playwright.config.ts now reads the cgroup v2 quota (/sys/fs/cgroup/cpu.max,
"400000 100000" in such a container) and uses that many workers; with no
quota (laptops, a host runner) Playwright keeps its own default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
poli0981andClaude Opus 5.5 committed 2026-12-05 10:25:48 +07:00
1 parent 8bb3ea5954
commit a3baf775b6
1 file changed
+22
+22
View File
@@ -16,8 +16,29 @@
// 429 page). Cloudflare's own edge is verified on production after each
// deploy (ci.yml `deploy`, docs/13 §3) — there are no preview versions since
// the move to Gitea (D38).
import { readFileSync } from 'node:fs';
import { defineConfig, devices } from '@playwright/test';
/**
* CPUs this process may actually use when a cgroup v2 quota caps it — the
* CI job container runs with `docker --cpus=4` (runner `anon-docker`, since
* 2026-12-04), yet `os.cpus()`, which Playwright sizes its pool by, still
* reports every core of the host (28). Fourteen workers on four CPUs made
* axe on /apps take over 30 s instead of ~9 s and time out. `undefined`
* (Playwright's own default) wherever no quota applies, laptops included.
*/
function cgroupCpuQuota(): number | undefined {
try {
const [quota, period] = readFileSync('/sys/fs/cgroup/cpu.max', 'utf8').trim().split(/\s+/);
if (quota === undefined || quota === 'max' || period === undefined) return undefined;
const cpus = Math.floor(Number(quota) / Number(period));
return Number.isFinite(cpus) ? Math.max(1, cpus) : undefined;
} catch {
return undefined;
}
}
const CPU_QUOTA = cgroupCpuQuota();
const PORT = 4321;
// Not wrangler's default 8787/8788: another project's `wrangler dev` may hold
// those, and reuseExistingServer would then test the wrong site.
@@ -27,6 +48,7 @@ const WORKER_SPEC = /worker\.spec\.ts$/;
export default defineConfig({
testDir: 'e2e',
fullyParallel: true,
...(CPU_QUOTA === undefined ? {} : { workers: CPU_QUOTA }),
forbidOnly: Boolean(process.env['CI']),
retries: process.env['CI'] ? 1 : 0,
// `list` in CI too: Gitea shows no annotations, so the github reporter's