test: deflake test-worker-eventlooputil

worker.performance.eventLoopUtilization() reads the worker's idle time
before the current time. If the parent thread stalls between the two
reads while the worker is idle, the stall is counted as worker active
time in the first sample and is missing from the delta, so the 50ms
spin can be reported as slightly less than 50ms.

Bound that skew by timing the first workerELU() call.

Signed-off-by: Matteo Collina <hello@matteocollina.com>
PR-URL: https://github.com/nodejs/node/pull/67260
Refs: https://github.com/nodejs/reliability/issues/1482
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
This commit is contained in:
Matteo Collina authored and Antoine du Hamel committed 2026-11-13 17:02:18 +01:00
1 parent 2b50db1364
commit 5ac48a96db
1 file changed
+7 -1
+7 -1
View File
@@ -95,13 +95,19 @@ function checkWorkerIdle(wElu) {
}
function checkWorkerActive() {
// Reading the worker's ELU from this thread is not atomic: the worker's idle
// time is read before the current time. If this thread stalls between the
// two reads while the worker is idle, the stall is counted as worker active
// time in `w` and then missing from `w2`. The duration of the call bounds it.
const start = performance.now();
const w = workerELU();
const skew = performance.now() - start;
metricsCh.port2.postMessage({ cmd: 'spin', dur: 50 });
metricsCh.port2.once('message', mustCall((wElu) => {
const w2 = workerELU(w);
assert.ok(w2.active >= 50, `${w2.active} < 50`);
assert.ok(w2.active >= 50 - skew, `${w2.active} < 50 - ${skew}`);
assert.ok(wElu.active >= 50, `${wElu.active} < 50`);
assert.ok(idleActive(wElu) < idleActive(w2),
`${idleActive(wElu)} >= ${idleActive(w2)}`);