test(e2e): Firefox 브라우저 프로필을 RAM 파일시스템에 둔다 #47
@@ -175,6 +175,7 @@ jobs:
|
||||
timeout-minutes: 45
|
||||
container:
|
||||
image: "mcr.microsoft.com/playwright:v1.62.0-noble@sha256:baed2032d533817f3dbe6425de795788430ba345e819a1201337009ba17c9d07"
|
||||
options: "--shm-size=2g"
|
||||
env:
|
||||
CI_RUNNER_IMAGE: "mcr.microsoft.com/playwright:v1.62.0-noble@sha256:baed2032d533817f3dbe6425de795788430ba345e819a1201337009ba17c9d07"
|
||||
steps:
|
||||
|
||||
@@ -8,7 +8,10 @@
|
||||
출력을 거절한다. `corepack pnpm check:ci`는 산출물 schema 검사, 타입이 있는 계약 검사기,
|
||||
이 workflow drift 검사를 돈다. merge 단계는 job 셋(`merge_static`, `merge_test`,
|
||||
`merge_browser`)으로 돌고 job마다 설치를 한 번 한다. 게이트마다 ID 이름의 step이 하나씩
|
||||
있고, 실패한 게이트가 다음 게이트를 건너뛰게 하지 않는다.
|
||||
있고, 실패한 게이트가 다음 게이트를 건너뛰게 하지 않는다. `merge_browser` 컨테이너는 `/dev/shm`을
|
||||
2 GB로 연다(`--shm-size=2g`). Firefox 시험 프로필을 RAM에 두기 위해서다
|
||||
(`tests/support/browser/browser-test.ts`). Docker 기본값 64 MB면 프로필이 runner 디스크에 남아
|
||||
Firefox의 첫 localStorage 접근이 수 초씩 기다렸다.
|
||||
|
||||
merge job 셋만 의존성 캐시를 쓴다(권하는 안으로 정함 2026-11-13, 총괄). setup-node 앞에서
|
||||
Node toolcache, corepack이 받은 pnpm, pnpm store와 메타데이터 캐시를 `.nvmrc`와
|
||||
|
||||
@@ -101,6 +101,7 @@
|
||||
| 그리는 중인 화면을 누른다 | 앱 뒤에 붙인 버튼이 렌더링 중 12 px 밀려 클릭이 닿지 않았다 | 테스트가 붙이는 조작 요소는 앱 레이아웃과 무관한 고정 층에 둔다. "다 그려질 때까지 기다리기"는 신호가 없어 쓰지 않는다(결함 패턴 T5) |
|
||||
| 짧은 상태를 폴링으로 잡는다 | 500 ms만 이어지는 `BLOCKED` 상태를 폴링으로 잡으려다 두 엔진에서 실패 | 상태 변화를 이벤트·기록으로 받는다 |
|
||||
| 고정 상한과 첫 실행 비용 | provider 테스트 10개가 10초 상한에 묶이고, 하나만 고르면 첫 테스트가 fixture 빌드를 떠안아 실패 | 무거운 준비는 suite 준비 단계로 옮기고 suite가 자기 timeout을 선언한다 |
|
||||
| 브라우저가 붐비는 디스크를 기다린다 | Firefox는 시험 context의 localStorage를 디스크의 프로필에 둔다. runner와 같이 쓰는 desktop SSD에서 context마다 첫 접근이 최대 8.2초 멈췄고, 첫 화면 5초 대기 안에서 실패했다. 프로필을 `/dev/shm`에 두면 최대 17 ms | Firefox 프로필은 RAM 파일시스템에 둔다(`tests/support/browser/browser-test.ts`). 자리가 없으면 그 사실과 이유를 한 줄로 알린다 |
|
||||
|
||||
## 6. 테스트 실행 비용
|
||||
|
||||
|
||||
@@ -210,7 +210,13 @@ function renderJob(
|
||||
` timeout-minutes: ${job.timeoutMinutes}`,
|
||||
);
|
||||
const image = jobImage(job);
|
||||
if (image) lines.push(" container:", ` image: ${yamlScalar(image)}`);
|
||||
if (image) {
|
||||
lines.push(
|
||||
" container:",
|
||||
` image: ${yamlScalar(image)}`,
|
||||
` options: ${yamlScalar(`--shm-size=${BROWSER_JOB_SHARED_MEMORY}`)}`,
|
||||
);
|
||||
}
|
||||
if (job.kind === "immutable") {
|
||||
const archive = job.steps.find((step) => step.kind === "archive-candidate");
|
||||
if (!archive || archive.kind !== "archive-candidate") throw new TypeError("immutable job lacks archive step");
|
||||
@@ -291,6 +297,16 @@ function gateHostPrefix(gate: Readonly<{ hostEnvironment?: "system-container" |
|
||||
return gate?.hostEnvironment === "system-container" ? "scripts/run-in-system-container.sh " : "";
|
||||
}
|
||||
|
||||
/**
|
||||
* /dev/shm of a browser job's container. Firefox's test profiles go there when
|
||||
* it has room for every worker (tests/support/browser/browser-test.ts): with a
|
||||
* profile on the runner's shared disk, Firefox's first localStorage access in
|
||||
* a context waited up to 8.2 s and failed first-screen waits (FE-GATE-008 and
|
||||
* FE-GATE-009, runs 127 and 266). Docker's default of 64 MB holds none; six
|
||||
* Firefox workers' profiles peaked at 211 MB together (2026-11-13).
|
||||
*/
|
||||
export const BROWSER_JOB_SHARED_MEMORY = "2g";
|
||||
|
||||
/** The Playwright image a browser job runs in (`browser-install.image`), if any. */
|
||||
function jobImage(job: CiWorkflowJob): string | undefined {
|
||||
for (const step of job.steps) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
import { expect, test } from "../support/browser/browser-test.ts";
|
||||
|
||||
// R3-7. The chunk-recovery classifier matches engine error wording. Run the
|
||||
// app's own classifier (served by the dev server) against the error each real
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import { readFile } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
|
||||
import { expect, test, type Page } from "@playwright/test";
|
||||
import type { Page } from "@playwright/test";
|
||||
|
||||
import { addGeneratedFeature } from "../../scripts/lib/generated-feature.ts";
|
||||
import { testRunPath } from "../../scripts/lib/run-isolation.ts";
|
||||
// The tracker's own tests run without the strict verdict, on the same
|
||||
// browser set-up as every other spec.
|
||||
import { expect, test } from "../support/browser/browser-test.ts";
|
||||
import { trackPreloadUse } from "../support/browser/preload-use.ts";
|
||||
import { test as strictTest } from "../support/browser/strict-browser-test.ts";
|
||||
import {
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
import { mkdtemp, readdir, rm, statfs } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
|
||||
import { test as base } from "@playwright/test";
|
||||
|
||||
export { expect } from "@playwright/test";
|
||||
|
||||
/**
|
||||
* The browser tests' base `test`: Playwright's, with each Firefox worker's
|
||||
* browser profile on a RAM filesystem. Every browser spec reaches it, through
|
||||
* tests/support/browser/strict-browser-test.ts or directly.
|
||||
*
|
||||
* Firefox keeps a test context's localStorage and IndexedDB in the profile on
|
||||
* disk (Chromium and WebKit keep them in memory), and the first localStorage
|
||||
* access of each context waits for that disk work. On desktop, whose SSD the
|
||||
* CI runner shares with every other job, that access took up to 8.2 s with
|
||||
* the profile in /tmp and never more than 17 ms with it in /dev/shm
|
||||
* (2026-11-13, six browsers at a time, 384 accesses each way). The app reads
|
||||
* the colour scheme preference before it renders, so a Firefox test spent the
|
||||
* wait inside its 5 s wait for the first screen: 19 of 463 Firefox app boots
|
||||
* took 0.7 to 3.8 s in eight full FE-GATE-008 runs, and none of 174 took more
|
||||
* than 14 ms in three Firefox runs with the profiles in RAM. The failures it
|
||||
* caused before were in `old-tab-chunk-recovery.spec.ts`,
|
||||
* `preload-use.spec.ts` and `platform-overview.spec.ts`.
|
||||
*/
|
||||
|
||||
/** `f_type` of a tmpfs in statfs(2). */
|
||||
const TMPFS_MAGIC = 0x0102_1994;
|
||||
|
||||
/** The RAM filesystem of Linux, the desktop and the CI job containers included. */
|
||||
const SHARED_MEMORY = "/dev/shm";
|
||||
|
||||
/**
|
||||
* Room for one Firefox profile. Six Firefox workers' profiles held 211 MB
|
||||
* together at their largest in a Firefox FE-GATE-008 run (2026-11-13).
|
||||
*/
|
||||
const PROFILE_ROOM_BYTES = 64 * 1024 * 1024;
|
||||
|
||||
type ProfileRoot = Readonly<{
|
||||
/** The directory for the profile when it is not the temp directory. */
|
||||
root?: string;
|
||||
/** Why the profile stays on disk. */
|
||||
note?: string;
|
||||
}>;
|
||||
|
||||
/**
|
||||
* Where this worker's Firefox makes its profile: the temp directory when it is
|
||||
* already in RAM, else a new directory in /dev/shm when that has room for
|
||||
* every worker's profile, else the temp directory on disk, with the reason.
|
||||
*/
|
||||
async function firefoxProfileRoot(workers: number): Promise<ProfileRoot> {
|
||||
const needed = workers * PROFILE_ROOM_BYTES;
|
||||
const notes: string[] = [];
|
||||
for (const candidate of [tmpdir(), SHARED_MEMORY]) {
|
||||
const space = await statfs(candidate).catch(() => undefined);
|
||||
if (space === undefined) {
|
||||
notes.push(`${candidate} is missing`);
|
||||
} else if (space.type !== TMPFS_MAGIC) {
|
||||
notes.push(`${candidate} is on disk`);
|
||||
} else if (space.bavail * space.bsize < needed) {
|
||||
notes.push(
|
||||
`${candidate} has ${Math.floor((space.bavail * space.bsize) / 2 ** 20)} MB free, ` +
|
||||
`${workers} workers need ${needed / 2 ** 20} MB`,
|
||||
);
|
||||
} else {
|
||||
return candidate === tmpdir()
|
||||
? {}
|
||||
: { root: await mkdtemp(path.join(candidate, "playwright-firefox-")) };
|
||||
}
|
||||
}
|
||||
return { note: `Firefox profiles stay on disk in ${tmpdir()}: ${notes.join("; ")}.` };
|
||||
}
|
||||
|
||||
/** TMPDIR as the worker started, put back once the browser has launched. */
|
||||
const workerTmpdir = process.env.TMPDIR;
|
||||
|
||||
function restoreTmpdir() {
|
||||
if (workerTmpdir === undefined) delete process.env.TMPDIR;
|
||||
else process.env.TMPDIR = workerTmpdir;
|
||||
}
|
||||
|
||||
export const test = base.extend<object, { firefoxProfileRoot: ProfileRoot }>({
|
||||
firefoxProfileRoot: [
|
||||
async ({ browserName }, use, workerInfo) => {
|
||||
const choice =
|
||||
browserName === "firefox" ? await firefoxProfileRoot(workerInfo.config.workers) : {};
|
||||
if (choice.note !== undefined) console.warn(choice.note);
|
||||
if (choice.root !== undefined) process.env.TMPDIR = choice.root;
|
||||
try {
|
||||
await use(choice);
|
||||
} finally {
|
||||
restoreTmpdir();
|
||||
if (choice.root !== undefined) await rm(choice.root, { recursive: true, force: true });
|
||||
}
|
||||
},
|
||||
{ scope: "worker" },
|
||||
],
|
||||
// Playwright sets up a fixture's dependencies in the order they are named,
|
||||
// so the root is chosen before Playwright's own `browser` launches and
|
||||
// makes its profile under os.tmpdir(). TMPDIR points at the root only until
|
||||
// then: nothing else the worker puts in the temp directory goes to RAM.
|
||||
browser: [
|
||||
async ({ firefoxProfileRoot, browser }, use) => {
|
||||
restoreTmpdir();
|
||||
const { root } = firefoxProfileRoot;
|
||||
if (root !== undefined && (await readdir(root)).length === 0) {
|
||||
throw new Error(
|
||||
`Firefox did not make its profile in ${root}: Playwright no longer reads ` +
|
||||
"os.tmpdir() when it launches a browser (or the browser was connected, not launched).",
|
||||
);
|
||||
}
|
||||
await use(browser);
|
||||
},
|
||||
{ scope: "worker" },
|
||||
],
|
||||
});
|
||||
@@ -1,10 +1,6 @@
|
||||
import {
|
||||
expect,
|
||||
test as base,
|
||||
type ConsoleMessage,
|
||||
type Page,
|
||||
} from "@playwright/test";
|
||||
import type { ConsoleMessage, Page } from "@playwright/test";
|
||||
|
||||
import { expect, test as base } from "./browser-test.ts";
|
||||
import { trackPreloadUse } from "./preload-use.ts";
|
||||
|
||||
/**
|
||||
|
||||
@@ -178,6 +178,7 @@ jobs:
|
||||
timeout-minutes: 45
|
||||
container:
|
||||
image: "mcr.microsoft.com/playwright:v1.62.0-noble@sha256:baed2032d533817f3dbe6425de795788430ba345e819a1201337009ba17c9d07"
|
||||
options: "--shm-size=2g"
|
||||
env:
|
||||
CI_RUNNER_IMAGE: "mcr.microsoft.com/playwright:v1.62.0-noble@sha256:baed2032d533817f3dbe6425de795788430ba345e819a1201337009ba17c9d07"
|
||||
steps:
|
||||
|
||||
@@ -3,7 +3,7 @@ import { readFileSync } from "node:fs";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { loadCiGateContract, PLAYWRIGHT_JOB_IMAGE_PATTERN } from "../../scripts/contracts/ci-gates.ts";
|
||||
import { renderCiWorkflow } from "../../scripts/generate-ci-workflow.ts";
|
||||
import { BROWSER_JOB_SHARED_MEMORY, renderCiWorkflow } from "../../scripts/generate-ci-workflow.ts";
|
||||
|
||||
/**
|
||||
* merge_browser runs in Playwright's own image so it does not download the
|
||||
@@ -36,7 +36,9 @@ describe("browser job image", () => {
|
||||
const job = workflow.slice(workflow.indexOf(" merge_browser:\n"), workflow.indexOf(" release_gate:\n"));
|
||||
expect(image?.kind === "browser-install" && image.image).toBeTruthy();
|
||||
const ref = image?.kind === "browser-install" ? image.image! : "";
|
||||
expect(job).toContain(` container:\n image: "${ref}"\n`);
|
||||
expect(job).toContain(
|
||||
` container:\n image: "${ref}"\n options: "--shm-size=${BROWSER_JOB_SHARED_MEMORY}"\n`,
|
||||
);
|
||||
expect(job).toContain(` env:\n CI_RUNNER_IMAGE: "${ref}"\n`);
|
||||
expect(job).not.toContain("playwright install");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user