From 7013ebfcbcfb8b5e8a078b06d6a752494534935a Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Wed, 4 Nov 2026 18:11:36 +0100 Subject: [PATCH] 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 --- test/sequential/test-worker-eventlooputil.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/sequential/test-worker-eventlooputil.js b/test/sequential/test-worker-eventlooputil.js index 39c6d723ff79..8c8a0e3d4b60 100644 --- a/test/sequential/test-worker-eventlooputil.js +++ b/test/sequential/test-worker-eventlooputil.js @@ -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)}`);