Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

test(perf): overlay-churn-settled lets each anchored entrance end, so its count does not follow the runner's speed (#10496)

Cindy Zhangb7e55a4cd6f5
diff --git a/apps/sandbox/perf/scenes.perf.spec.ts b/apps/sandbox/perf/scenes.perf.spec.ts
index 5b9213a42a..2fd5c7d93b 100644
--- a/apps/sandbox/perf/scenes.perf.spec.ts
+++ b/apps/sandbox/perf/scenes.perf.spec.ts
@@ -4,7 +4,9 @@
* @file scenes.perf.spec.ts
* @input The built Sandbox's perf scenes page (apps/sandbox/out, served here
* by the accessibility harness's static server), PERF_SAMPLES (default 5),
- * PERF_RESULTS_DIR (default test-results/perf)
+ * PERF_RESULTS_DIR (default test-results/perf), PERF_CPU_THROTTLE (default
+ * 1: Chromium's CPU slowed this many times, to check that a count does not
+ * follow the runner's speed)
* @output One JSON file per scene: every sample and the per-metric median
* @position The perf scenes' measurement driver. Run locally with
* `pnpm build && pnpm -F @astryxdesign/sandbox build` then
@@ -36,10 +38,16 @@ import {
import {EVENT_TIMING_LOG, measureScene, type SceneSample} from './measure';
const SAMPLES = positiveInteger('PERF_SAMPLES', 5);
+const CPU_THROTTLE = positiveInteger('PERF_CPU_THROTTLE', 1);
const RESULTS_DIR = path.resolve(
process.env.PERF_RESULTS_DIR ?? 'test-results/perf',
);
const OVERLAY_CYCLES = 50;
+// Longer than an anchored overlay's entrance (the Sandbox theme's
+// `--duration-fast-max`, 165 ms), so each Popover and DropdownMenu entrance
+// plays out before Escape. The Dialog's entrance (400 ms) does not. It is not
+// anchored and lays out once per open, whenever Escape arrives.
+const ENTRANCE_SETTLE_MS = 250;
const SANDBOX_DIR = 'apps/sandbox/out';
let server: StaticServer | undefined;
@@ -63,16 +71,52 @@ function positiveInteger(name: string, fallback: number): number {
return value;
}
+type Overlay = 'popover' | 'menu' | 'dialog';
+
+/**
+ * Waits until the scene's overlay of `kind` is open or closed. It polls on a
+ * timer and reads only the open state, never style or layout. A locator's
+ * wait reads the element's style and box on every poll, so its cost follows
+ * how many polls fit into an entrance.
+ */
+async function waitForOverlay(
+ page: Page,
+ kind: Overlay,
+ open: boolean,
+): Promise<void> {
+ await page.waitForFunction(
+ ({overlay, expected}) => {
+ let isOpen: boolean;
+ if (overlay === 'dialog') {
+ isOpen = [...document.querySelectorAll('dialog[open]')].some(dialog =>
+ dialog.textContent?.includes('Perf dialog'),
+ );
+ } else {
+ const text = overlay === 'menu' ? 'Rename' : 'Popover content';
+ isOpen = [...document.querySelectorAll('[popover]')].some(
+ layer =>
+ layer.matches(':popover-open') &&
+ (layer.textContent ?? '').includes(text),
+ );
+ }
+ return isOpen === expected;
+ },
+ {overlay: kind, expected: open},
+ {polling: 50},
+ );
+}
+
/** Plays one open/close of an overlay with real input. */
async function openAndClose(
page: Page,
trigger: string,
- shown: ReturnType<Page['locator']>,
+ kind: Overlay,
): Promise<void> {
await page.getByRole('button', {name: trigger, exact: true}).click();
- await shown.waitFor({state: 'visible'});
+ await waitForOverlay(page, kind, true);
+ await page.waitForTimeout(ENTRANCE_SETTLE_MS);
await page.keyboard.press('Escape');
- await shown.waitFor({state: 'hidden'});
+ await waitForOverlay(page, kind, false);
}
/** Each scene's interaction, played with real input after it mounted. */
@@ -111,15 +155,13 @@ const INTERACTIONS: Readonly<
.click();
await frames(page, 2);
},
- // Open and close each overlay, OVERLAY_CYCLES times.
- 'overlay-churn': async page => {
- const popover = page.getByText('Popover content');
- const menu = page.getByRole('menuitem', {name: 'Rename', exact: true});
- const dialog = page.getByRole('dialog', {name: 'Perf dialog', exact: true});
+ // Open each overlay, let an anchored overlay's entrance end, and close it,
+ // OVERLAY_CYCLES times.
+ 'overlay-churn-settled': async page => {
for (let cycle = 0; cycle < OVERLAY_CYCLES; cycle++) {
- await openAndClose(page, 'Open popover', popover);
- await openAndClose(page, 'Open menu', menu);
- await openAndClose(page, 'Open dialog', dialog);
+ await openAndClose(page, 'Open popover', 'popover');
+ await openAndClose(page, 'Open menu', 'menu');
+ await openAndClose(page, 'Open dialog', 'dialog');
}
},
};
@@ -142,6 +184,12 @@ for (const scene of PERF_SCENES) {
});
try {
const page = await context.newPage();
+ if (CPU_THROTTLE > 1) {
+ const cdp = await context.newCDPSession(page);
+ await cdp.send('Emulation.setCPUThrottlingRate', {
+ rate: CPU_THROTTLE,
+ });
+ }
await page.addInitScript(EVENT_TIMING_LOG);
await page.goto(`/pages/perf-scenes/?scene=${scene}`);
await page
diff --git a/apps/sandbox/src/app/(raw)/pages/perf-scenes/sceneIds.ts b/apps/sandbox/src/app/(raw)/pages/perf-scenes/sceneIds.ts
index 7c45e43a56..80ba4c43dd 100644
--- a/apps/sandbox/src/app/(raw)/pages/perf-scenes/sceneIds.ts
+++ b/apps/sandbox/src/app/(raw)/pages/perf-scenes/sceneIds.ts
@@ -16,7 +16,7 @@ export const PERF_SCENES = [
'table',
'tree-list',
'markdown',
- 'overlay-churn',
+ 'overlay-churn-settled',
] as const;
export type PerfSceneId = (typeof PERF_SCENES)[number];
@@ -27,7 +27,8 @@ export const PERF_SCENE_LABELS: Readonly<Record<PerfSceneId, string>> = {
table: 'Table: 1,000 rows, sort and filter',
'tree-list': 'TreeList: 500 items with animated layout, expand all',
markdown: 'Markdown: a long document with tables and code blocks',
- 'overlay-churn': 'Overlay churn: Popover, DropdownMenu and Dialog',
+ 'overlay-churn-settled':
+ 'Overlay churn: Popover, DropdownMenu and Dialog, each anchored entrance played out',
};
export function parsePerfScene(value: string | null): PerfSceneId {
diff --git a/apps/sandbox/src/app/(raw)/pages/perf-scenes/scenes.tsx b/apps/sandbox/src/app/(raw)/pages/perf-scenes/scenes.tsx
index 4d6cb3b2e1..5693915fca 100644
--- a/apps/sandbox/src/app/(raw)/pages/perf-scenes/scenes.tsx
+++ b/apps/sandbox/src/app/(raw)/pages/perf-scenes/scenes.tsx
@@ -277,7 +277,7 @@ const SCENES: Readonly<Record<PerfSceneId, () => React.ReactNode>> = {
table: TableScene,
'tree-list': TreeListScene,
markdown: MarkdownScene,
- 'overlay-churn': OverlayChurnScene,
+ 'overlay-churn-settled': OverlayChurnScene,
};
export function PerfScene({scene}: {scene: PerfSceneId}) {
diff --git a/docs/specs/AST-030/spec.md b/docs/specs/AST-030/spec.md
index 2ae8b5d088..00e2a83319 100644
--- a/docs/specs/AST-030/spec.md
+++ b/docs/specs/AST-030/spec.md
@@ -447,7 +447,9 @@ they are separately named.
maintain or admin access, under the same label rule and timing as FR12's suite
labels and FR17, and only when its paths touch what the scenes measure (FR14);
a pull request run is compared with the same history and records nothing. The
- lane runs on standard runners within the pull-request job budget.
+ lane runs on standard runners within the pull-request job budget. During a
+ measured interaction, a scene's driver adds no rendering work whose amount
+ depends on the runner's speed.
- **FR19 — A pull request that changes CI states its CI impact.** A pull
request that changes a workflow, a composite action or a CI script carries
its CI impact in its description's `CI impact:` line: each changed job's
@@ -657,6 +659,7 @@ The nightly perf lane is the one scheduled measurement outside them (FR18).
| FR16 | `ci-admission.test.mjs` cases for one start at the longest wait at a time and the workflow contract | a pull-request run at its longest wait alone, within ten minutes of another pull-request run's start there and after them, behind a run that waited longer and ahead of a younger one; another run that found room earlier, a fork's stopped run and a `main` run that waited its longest; a `main` run and a merge-queue entry at their longest wait; the rest of a run whose Storybook build found room; ten runs out of time together; the required contexts and ci-full for either wait; a pull-request run that finds ten others waiting and room only for its Storybook build, and one at its longest wait behind more than ten that waited longer; two waiting `main` dispatches, the older and the younger, and two that began in the same second (each counting the other's peak fails) | two pull-request runs start at their longest wait within ten minutes, a younger run starts ahead of a longer waiter, a `main` run or merge-queue entry stops, a run CI is full for builds, or a required context passes or skips |
| FR17 | `ci-pr-gate.test.mjs` over every `pull_request` workflow and the shared conditions | branch here, fork with and without `ci:run`, another label, draft with the label, ready, push, merge group, dispatch | a job that can start on a pull request without the condition, a label trigger, a required job that skips for a pull request that may not run CI, or a draft or unlabelled fork that runs fails |
| FR18 | `perf-nightly-workflow.test.mjs`, `perf-trend.test.mjs` and `run-labels.test.mjs` | nightly and dispatch; labelled, unlabelled, draft and unvouched-fork pull requests; write, read and no access; newest label event; failed lookup; 10% boundary; metric floors; seven-day window edges; fewer than three runs; a metric over once, twice in a row, or a different metric before; recorded and pull request runs | a run on an unlabelled pull request, a label honoured from read access, a regression called at exactly 10%, under its floor or on one run alone, a run outside the window in the baseline, a pull request run that records, or a second regression issue fails |
+| FR18 | `overlay-churn-settled` on one commit, five samples per run | medians within 1% between a standard run and a `PERF_CPU_THROTTLE=4` run on the same runner (Chromium's CPU slowed four times) | interaction-layout medians more than 1% apart fail |
| FR19 | `ci-impact.test.mjs`, `pr-preview.test.mjs` and the maintenance template | CI change and non-CI change; standard, non-standard and expression runners; added, removed and changed jobs; trigger change | a CI change reports no impact, a move onto a non-standard runner or a pool or time-to-green rise past its threshold goes unflagged, or the section names a price |
| FR20 | `ci-heavy-deferral.test.mjs` over ci.yml, lint.yml and pr-comment.yml | agent push; marked ready; opened; reopened; re-run; another author; release branch; merge-back; spec-only change; Lab-only change; a release-check and an opt-in label run, where the decision skips; a failed-jobs re-run of a deferred push | a heavy job runs on a deferred push, a required context passes or skips on one, a ready, reopened or re-run pull request defers, a spec-only or Lab-only change defers, the report hides the deferral, or a job below the decision skips because it skipped |
| FR21 | `ci-heavy-lanes.test.mjs` dispatch cases, `main-unit-run.test.mjs` over deploy.yml, `release-check-receipt.test.mjs` | push run; dispatched unit run; tip with the scheduler's or a person's release-check, or a person's maintenance capture; unit run cancelled, skipped or timed out; newer recheck or person's run of the tip; a person's validation of an older commit; cut commit with and without a passing unit run | a push runs the unit suites, a push cancels a unit run, a release-check comes without a unit run of its commit, an incomplete run goes unreported or waits a window, or a cut publishes without a passing unit run |
diff --git a/packages/core/src/Layer/__tests__/LayerCloseLayout.interaction.browser.spec.ts b/packages/core/src/Layer/__tests__/LayerCloseLayout.interaction.browser.spec.ts
index f26205246b..1c4984cd8c 100644
--- a/packages/core/src/Layer/__tests__/LayerCloseLayout.interaction.browser.spec.ts
+++ b/packages/core/src/Layer/__tests__/LayerCloseLayout.interaction.browser.spec.ts
@@ -25,7 +25,7 @@ import {
const storybook = withStorybook(test);
-// A desktop page, as the overlay-churn perf scene measures: on a phone, a
+// A desktop page, as the overlay-churn-settled perf scene measures: on a phone, a
// Popover plays its own close motion, which lays out on every frame.
test.use({
viewport: {width: 1280, height: 800},
diff --git a/playwright.perf.config.ts b/playwright.perf.config.ts
index 28fc078316..e7e4e43c57 100644
--- a/playwright.perf.config.ts
+++ b/playwright.perf.config.ts
@@ -29,8 +29,10 @@ export default defineConfig({
workers: 1,
fullyParallel: false,
// A scene's samples run inside one test, each with a warm-up cycle; overlay
- // churn plays 150 open/close pairs per cycle.
- timeout: 6 * 60_000,
+ // churn plays 150 open/close pairs per cycle and lets each anchored
+ // entrance end.
+ // It stays inside the 15-minute job budget.
+ timeout: 13 * 60_000,
forbidOnly: isCI,
reporter: isCI ? [['list'], ['github']] : [['list']],
projects: [{name: 'chromium', use: {...devices['Desktop Chrome']}}],