Skip to content

Commit 8484dc4

Browse files
vjeuxcixzhang
andauthored
test(interaction-harness): a pool leaves out a run that began too late (#10464)
* test(interaction-harness): a pool leaves out a run that began too late A run whose block began after its motion had settled made the whole pooled proof throw BusyWindowTooLateError, while a starved run was only left out. A run that began too late holds nothing to judge either, so the pool now leaves it out the same way and names it. Its runs entry is null and late holds the error. The floors are unchanged: a pool with fewer judged runs than its minimum, counted over all the runs, fails by name. * Merge branch 'main' into test/harness-pool-late-runs Co-authored-by: Cindy Zhang <cindyxz@meta.com>
1 parent 3890d68 commit 8484dc4

4 files changed

Lines changed: 109 additions & 22 deletions

File tree

‎internal/interaction-harness/README.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,10 @@ frames over all the runs, the component on every one of them, and in each run
328328
its longest stall may be no longer than that run's control's, since a stall
329329
belongs to its run. A run whose control moved on fewer frames than
330330
`minRunFrames` (1 by default) is too little to judge: the summary names it,
331-
and the pool leaves it out, so it never counts as a pass. The pool fails with
332-
fewer than `minJudgedRuns` judged runs (half, rounded up). In each judged run,
331+
and the pool leaves it out, so it never counts as a pass. A run whose block
332+
began after its motion had settled is left out the same way: its `runs` entry
333+
is null, and `late` holds its `BusyWindowTooLateError`. The pool fails with
334+
fewer than `minJudgedRuns` judged runs (half of all the runs, rounded up). In each judged run,
333335
the component must move on every frame its control moved on, so a freeze fails
334336
its run.
335337

‎internal/interaction-harness/src/busy.control.test.ts‎

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818

1919
import {describe, expect, it} from 'vitest';
20-
import {busyWindowProof, pooledBusyProof} from './busy';
20+
import {busyWindowProof, BusyWindowTooLateError, pooledBusyProof} from './busy';
2121
import type {TrackedFrame} from './frames';
2222

2323
const FRAME = 1000 / 60;
@@ -303,6 +303,58 @@ describe('pooledBusyProof', () => {
303303
);
304304
});
305305

306+
it('leaves out a run whose block began after its motion had settled, and names it', () => {
307+
const control = asControl(moving());
308+
// Settled 50 ms before the run's block: nothing in it is left to judge.
309+
const settled = moving().map(f =>
310+
f.t < 950
311+
? f
312+
: ({...f, box: {...f.box!, y: 3 * at(950)}} as TrackedFrame),
313+
);
314+
const pooled = pooledBusyProof(
315+
[
316+
{tracked: settled, control, window: short(1000)},
317+
{tracked: moving(), control, window: short(1300)},
318+
{tracked: moving(), control, window: short(1600)},
319+
],
320+
{settledWithin: 2},
321+
);
322+
expect(pooled.verdict.failures, pooled.summary).toEqual([]);
323+
expect(pooled.judged).toEqual([false, true, true]);
324+
expect(pooled.runs[0]).toBeNull();
325+
expect(pooled.late[0]).toBeInstanceOf(BusyWindowTooLateError);
326+
expect(pooled.late.slice(1)).toEqual([null, null]);
327+
// Only the judged runs' frames count toward the pool's floors.
328+
expect(pooled.control).toEqual({moved: 6, movedWith: 6});
329+
expect(pooled.summary).toMatch(
330+
/^3 runs pooled, 2 judged: .*; run 1: too late to judge: busyWindowProof: /,
331+
);
332+
});
333+
334+
it('fails by name a pool left with fewer judged runs than its minimum, however many began too late', () => {
335+
const control = asControl(moving());
336+
const settled = moving().map(f =>
337+
f.t < 950
338+
? f
339+
: ({...f, box: {...f.box!, y: 3 * at(950)}} as TrackedFrame),
340+
);
341+
// One long run passes every floor alone, beside two that began too late.
342+
const pooled = pooledBusyProof(
343+
[
344+
{tracked: settled, control, window: short(1000)},
345+
{tracked: settled, control, window: short(1000)},
346+
{tracked: moving(), control, window: {from: 1100, to: 1700}},
347+
],
348+
{settledWithin: 2},
349+
);
350+
expect(pooled.verdict.pass).toBe(false);
351+
expect(pooled.verdict.failures).toEqual([
352+
'1 of 3 runs judged, under 2: 2 began after the motion had settled, and the compositor presented too little in any other to judge',
353+
]);
354+
expect(pooled.summary).toMatch(/run 1: too late to judge/);
355+
expect(pooled.summary).toMatch(/run 2: too late to judge/);
356+
});
357+
306358
it('still fails a component that is frozen in every run while the control moves', () => {
307359
const frozen = moving().map(
308360
f => ({...f, box: {...f.box!, y: 0}}) as TrackedFrame,

‎internal/interaction-harness/src/busy.ts‎

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,10 +1580,17 @@ export interface PooledBusyProof {
15801580
* Each run judged on its own against its control: read its numbers, not its
15811581
* verdict (one short run can hold too few frames to judge).
15821582
*/
1583-
readonly runs: readonly BusyProof[];
1583+
readonly runs: readonly (BusyProof | null)[];
1584+
/**
1585+
* For each run, the `BusyWindowTooLateError` its window threw, or null. Such
1586+
* a run's block began after its motion had settled, so its `runs` entry is
1587+
* null: the run holds nothing to judge.
1588+
*/
1589+
readonly late: readonly (BusyWindowTooLateError | null)[];
15841590
/**
15851591
* Whether each run was judged. A run whose control moved on fewer than
1586-
* `minRunFrames` frames is too little to judge, and the pool leaves it out.
1592+
* `minRunFrames` frames is too little to judge, and so is a run that began
1593+
* too late (`late`). The pool leaves both out.
15871594
*/
15881595
readonly judged: readonly boolean[];
15891596
/**
@@ -1604,7 +1611,9 @@ export interface PooledBusyProof {
16041611
* present fewer than `minJudgedFrames` in one run, and one run cannot decide.
16051612
* A run whose control moved on fewer than `minRunFrames` frames (1 by
16061613
* default) is too little to judge: the machine starved it. The summary names
1607-
* it, and the pool leaves it out, so it never counts as a pass.
1614+
* it, and the pool leaves it out, so it never counts as a pass. A run whose
1615+
* window throws `BusyWindowTooLateError` is left out the same way: its block
1616+
* began after its motion had settled.
16081617
* The judged runs are judged as one long window is:
16091618
* - at least `minJudgedRuns` runs are judged (by default, half the runs,
16101619
* rounded up);
@@ -1644,15 +1653,31 @@ export function pooledBusyProof(
16441653
`pooledBusyProof: minJudgedRuns ${minJudgedRuns} is not between 1 and the ${runs.length} runs`,
16451654
);
16461655
}
1647-
const proofs = runs.map(run =>
1648-
busyWindowProof(run.tracked, run.window, {
1649-
...windowOptions,
1650-
control: run.control,
1651-
}),
1656+
const late: (BusyWindowTooLateError | null)[] = [];
1657+
const proofs = runs.map(run => {
1658+
try {
1659+
const proof = busyWindowProof(run.tracked, run.window, {
1660+
...windowOptions,
1661+
control: run.control,
1662+
});
1663+
late.push(null);
1664+
return proof;
1665+
} catch (error) {
1666+
if (!(error instanceof BusyWindowTooLateError)) {
1667+
throw error;
1668+
}
1669+
late.push(error);
1670+
return null;
1671+
}
1672+
});
1673+
const reads = proofs.map(proof =>
1674+
proof == null ? null : (proof.control as BusyControlRead),
16521675
);
1653-
const reads = proofs.map(proof => proof.control as BusyControlRead);
1654-
const judged = reads.map(read => read.moved >= minRunFrames);
1655-
const judgedReads = reads.filter((_, i) => judged[i]);
1676+
const judged = reads.map(read => read != null && read.moved >= minRunFrames);
1677+
const judgedReads = reads.filter(
1678+
(read, i): read is BusyControlRead => judged[i] && read != null,
1679+
);
1680+
const lateRuns = late.filter(error => error != null).length;
16561681
const total = (key: 'moved' | 'movedWith' | 'belowStep') =>
16571682
judgedReads.reduce((sum, read) => sum + read[key], 0);
16581683
const moved = total('moved');
@@ -1664,7 +1689,9 @@ export function pooledBusyProof(
16641689
const failures: string[] = [];
16651690
if (judgedReads.length < minJudgedRuns) {
16661691
failures.push(
1667-
`${judgedReads.length} of ${runs.length} runs judged, under ${minJudgedRuns}: the compositor presented too little in the others to judge`,
1692+
lateRuns === 0
1693+
? `${judgedReads.length} of ${runs.length} runs judged, under ${minJudgedRuns}: the compositor presented too little in the others to judge`
1694+
: `${judgedReads.length} of ${runs.length} runs judged, under ${minJudgedRuns}: ${lateRuns} began after the motion had settled, and the compositor presented too little in any other to judge`,
16681695
);
16691696
}
16701697
if (judgedReads.length > 0 && moved < minJudgedFrames) {
@@ -1684,15 +1711,18 @@ export function pooledBusyProof(
16841711
);
16851712
}
16861713
proofs.forEach((proof, i) => {
1714+
if (proof == null) {
1715+
return;
1716+
}
16871717
if (proof.frames > 0 && proof.medianFrameMs > maxMedianFrameMs) {
16881718
failures.push(
16891719
`run ${i + 1}: median frame interval ${proof.medianFrameMs.toFixed(1)} ms > ${maxMedianFrameMs} ms`,
16901720
);
16911721
}
1692-
if (!judged[i]) {
1722+
const read = reads[i];
1723+
if (!judged[i] || read == null) {
16931724
return;
16941725
}
1695-
const read = reads[i];
16961726
if (read.movedWith < read.moved) {
16971727
failures.push(
16981728
`run ${i + 1}: moved on ${read.movedWith} of the ${read.moved} frames its control moved`,
@@ -1712,13 +1742,16 @@ export function pooledBusyProof(
17121742
`: moved on ${movedWith} of the control's ${moved} frames` +
17131743
proofs
17141744
.map((proof, i) =>
1715-
judged[i]
1716-
? `; run ${i + 1}: ${proof.summary}`
1717-
: `; run ${i + 1}: too little to judge, the control moved on ${reads[i].moved} frames, under ${minRunFrames}: ${proof.summary}`,
1745+
proof == null
1746+
? `; run ${i + 1}: too late to judge: ${late[i]?.message ?? ''}`
1747+
: judged[i]
1748+
? `; run ${i + 1}: ${proof.summary}`
1749+
: `; run ${i + 1}: too little to judge, the control moved on ${reads[i]?.moved ?? 0} frames, under ${minRunFrames}: ${proof.summary}`,
17181750
)
17191751
.join('');
17201752
return {
17211753
runs: proofs,
1754+
late,
17221755
judged,
17231756
control: {moved, movedWith},
17241757
verdict: {pass: failures.length === 0, failures},

‎packages/core/src/hooks/__tests__/usePager.interaction.browser.spec.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,11 +1186,11 @@ test('a settle keeps advancing every frame through an 800 ms main-thread block',
11861186
expect(proof.verdict.failures, proof.summary).toEqual([]);
11871187
// Each run's own block has to show the settle at a new position.
11881188
proof.runs.forEach((run, i) => {
1189-
const read = run.control;
1189+
const read = run?.control;
11901190
const settleFrames = (read?.movedWith ?? 0) - (read?.belowStep ?? 0);
11911191
expect(
11921192
settleFrames,
1193-
`run ${i + 1}: the settle showed a new position on ${settleFrames} frames in its block. ${run.summary}`,
1193+
`run ${i + 1}: the settle showed a new position on ${settleFrames} frames in its block. ${run?.summary ?? proof.late[i]?.message}`,
11941194
).toBeGreaterThanOrEqual(1);
11951195
});
11961196
});

0 commit comments

Comments
 (0)