feedback5 WZ: the waitForFunctionLong slicing test counts slices, not milliseconds (test/e2e/client-wait.test.js slicedPage)

Its fake predicate turned true 95 ms after the page was made and the test wanted at least 4 slices of 30 ms. On a loaded
machine the 30 ms timers fire late and merge the slices: the 0.2.0 candidate's full pass got 'sliced (3 calls)'. A
preload that blocks the event loop 9 ms of every 12 reproduces it 5 of 5 times. Now the predicate holds on the 4th call:
exactly 4 calls, each with the same predicate, args and polling, each slice 0–30 ms, and the wait lasted the three
slices (≥ 85 ms). It passes 5 of 5 under that lag and under 25 ms of every 27. A helper that stops at the first
timed-out slice still fails it. A test timing flake, no product change; golden unchanged.
This commit is contained in:
sganggs committed 2026-10-06 21:08:33 +08:00
1 parent 205bca7a07
commit bb46713718
1 file changed
+25 -3
+25 -3
View File
@@ -27,12 +27,34 @@ function fakePage(trueAfter) {
};
}
/**
* A page whose predicate holds from its `holdsOn`-th waitForFunction call on; each earlier slice times out after its own
* timeout, like puppeteer's. Counted in calls, not in wall time: on a loaded machine late timers merge time-based slices
* (fakePage(95) with 30 ms slices returned in 3 calls instead of 4 in the 0.2.0 candidate's full pass).
*/
function slicedPage(holdsOn) {
const calls = [];
return {
calls,
waitForFunction(fn, opts, ...args) {
calls.push({ fn, opts, args });
const holds = calls.length >= holdsOn;
return new Promise((resolve, reject) => {
if (holds) setTimeout(() => resolve({ handle: 'ok', args }), 0);
else setTimeout(() => reject(timeoutError(opts.timeout)), opts.timeout);
});
},
};
}
test('a wait longer than one slice keeps polling the same predicate until it holds', async () => {
const page = fakePage(95);
const page = slicedPage(4);
const fn = () => true;
const got = await waitForFunctionLong(page, fn, { timeout: 1000, polling: 200, slice: 30 }, 'a', 2);
const t0 = Date.now();
const got = await waitForFunctionLong(page, fn, { timeout: 60_000, polling: 200, slice: 30 }, 'a', 2);
assert.deepEqual(got, { handle: 'ok', args: ['a', 2] });
assert.ok(page.calls.length >= 4, `sliced (${page.calls.length} calls)`);
assert.equal(page.calls.length, 4, 'three slices ran out, the fourth held, nothing polled after it');
assert.ok(Date.now() - t0 >= 85, `the three slices waited their 30 ms each (${Date.now() - t0} ms)`);
for (const c of page.calls) {
assert.equal(c.fn, fn);
assert.deepEqual(c.args, ['a', 2]);