Skip to content

Commit d415170

Browse files
authored
test(element): bound max-fps by the rate, not by the machine (#6)
The release dry run failed on WebKit with free=8, held=4: the cap working exactly as specified, and the assertion collapsing because the uncapped run had itself been throttled to around 20fps by a loaded runner. Requiring the capped run to paint less than half of an unbounded measurement makes the test a measurement of the machine. paint() holds a frame whenever `now - painted < 1000 / fps`, so two paints are at least that far apart and a window of ms fits at most floor(ms / interval) + 1 of them. That bound comes from the setting. A slow runner paints fewer and still satisfies it. The uncapped comparison is kept, but only where the uncapped run actually outran the cap — elsewhere it is evidence of nothing, which is the same reason the accessibility suite probes for full keyboard access rather than assuming it. Mutation-tested: removing the throttle gate fails the bound on all three engines (49, 25, 49 against a permitted 5).
1 parent 0281757 commit d415170

1 file changed

Lines changed: 32 additions & 15 deletions

File tree

‎test/browser/element.test.ts‎

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -312,27 +312,44 @@ describe("when the canvas is painted", () => {
312312
};
313313

314314
/**
315-
* Both rates measured in the same run, and compared against each other.
315+
* The bound comes from the setting, not from the machine.
316316
*
317-
* An absolute count would be measuring the machine: how many frames fit in
318-
* 400ms is the runner's business, not this code's. The claim worth pinning
319-
* is the ratio — capping at ten a second paints far less than following the
320-
* display, whatever the display happens to be.
317+
* `paint()` holds a frame whenever `now - painted < 1000 / fps`, so two paints
318+
* are at least that far apart and a window of `ms` fits at most
319+
* `floor(ms / interval) + 1` of them. A slow runner paints fewer, which still
320+
* satisfies the bound — that is the point of stating it this way.
321+
*
322+
* An earlier version compared the capped run against an uncapped one and
323+
* required half as many paints. That measures the runner: it failed on WebKit
324+
* in CI with free=8, held=4 — the cap working exactly as specified, and the
325+
* ratio collapsing because the uncapped run had itself been throttled to
326+
* around 20fps by a loaded machine.
321327
*/
322-
it("paints far less often when a rate is asked for", async () => {
328+
it("paints no more often than the rate it was given", async () => {
329+
const ms = 400;
330+
const fps = 10;
331+
const permitted = Math.floor(ms / (1000 / fps)) + 1;
332+
323333
const uncapped = await mount({ length: 64 * 1024 });
324334
const free = counting(uncapped.engine);
325-
await scrollFor(uncapped.engine, 400);
335+
await scrollFor(uncapped.engine, ms);
326336

327-
const capped = await mount({ length: 64 * 1024, attributes: { "max-fps": "10" } });
328-
expect(capped.element.maxFps).toBe(10);
337+
const capped = await mount({ length: 64 * 1024, attributes: { "max-fps": String(fps) } });
338+
expect(capped.element.maxFps).toBe(fps);
329339
const held = counting(capped.engine);
330-
await scrollFor(capped.engine, 400);
331-
332-
expect(free.paints, "the uncapped editor painted nothing; the driver is broken")
333-
.toBeGreaterThan(4);
334-
expect(held.paints, "the cap painted as often as no cap")
335-
.toBeLessThan(free.paints / 2);
340+
await scrollFor(capped.engine, ms);
341+
342+
expect(held.paints, "painted more often than the rate allows")
343+
.toBeLessThanOrEqual(permitted);
344+
expect(held.paints, "the cap painted nothing at all")
345+
.toBeGreaterThan(0);
346+
347+
// Only evidence when the uncapped run actually outran the cap. Where it did
348+
// not, it says nothing either way, and asserting on it would be measuring
349+
// the runner again.
350+
if (free.paints > permitted) {
351+
expect(held.paints, "capping did not reduce painting").toBeLessThan(free.paints);
352+
}
336353
});
337354

338355
it("still lands the final state after the last change", async () => {

0 commit comments

Comments
 (0)