Style: make waitFor a const arrow and trim its comment to current behavior

Both changes requested in review.

waitFor was declared with `async function`; AGENTS.md requires new functions
to use const arrow syntax, matching `tick` directly above it.

The comment's middle paragraph narrated the removed 80ms sleep and the
failure it produced. That history belongs to the PR, not the source. The
remaining text states only the current constraint: the run spans a POST plus
up to three real pollInterval timers, so no constant works, and the timeout
only bounds a hang.

Greptile's P1 on the `await tick()` before `scope.stop()` is deliberately not
applied, per the maintainer's analysis: Node fires expired timers in expiry
order and drains microtasks between callbacks, so the assertion, stop() and
clearTimeout all complete before the 50ms poll could run. Removing the tick
is the riskier direction.

No behavior change. tests/composable-globalping-measurement.test.js 22/22;
full `pnpm check` 1139/1139 plus build green. Re-ran the mutation control
after the edit: deleting clearTimeout from cancel() still fails exactly the
disposal case (21 pass, 1 fail), so the style change did not weaken it.
This commit is contained in:
Victor Solano committed 2026-08-25 14:42:40 +02:00
1 parent 9ab4505c60
commit 7ed58d8330
1 file changed
+3 -5
@@ -47,19 +47,17 @@ const tick = () => new Promise((r) => setTimeout(r, 0));
//
// A fixed sleep cannot do this job: a run here spans a POST plus up to three
// real `pollInterval` timers, so any constant is either flaky when the machine
// is loaded or slow on every green run. The "retries while in-progress" case
// used to allow 80ms for that chain and failed under a parallel suite with
// status still 'running' — a wait that expired, reported as a wrong result.
// is loaded or slow on every green run.
//
// The timeout only bounds a hang; it is never reached on a passing run.
async function waitFor(predicate, { timeout = 2000, label = 'condition' } = {}) {
const waitFor = async (predicate, { timeout = 2000, label = 'condition' } = {}) => {
const deadline = Date.now() + timeout;
for (;;) {
if (predicate()) return;
if (Date.now() > deadline) throw new Error(`timed out after ${timeout}ms waiting for ${label}`);
await tick();
}
}
};
describe('useGlobalpingMeasurement()', () => {
beforeEach(() => {