Skip to content

Commit d6b8579

Browse files
mcollinaaduh95
authored andcommitted
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: #67260 Refs: nodejs/reliability#1482 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
1 parent 829afea commit d6b8579

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

‎test/sequential/test-worker-eventlooputil.js‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,19 @@ function checkWorkerIdle(wElu) {
9595
}
9696

9797
function checkWorkerActive() {
98+
// Reading the worker's ELU from this thread is not atomic: the worker's idle
99+
// time is read before the current time. If this thread stalls between the
100+
// two reads while the worker is idle, the stall is counted as worker active
101+
// time in `w` and then missing from `w2`. The duration of the call bounds it.
102+
const start = performance.now();
98103
const w = workerELU();
104+
const skew = performance.now() - start;
99105

100106
metricsCh.port2.postMessage({ cmd: 'spin', dur: 50 });
101107
metricsCh.port2.once('message', mustCall((wElu) => {
102108
const w2 = workerELU(w);
103109

104-
assert.ok(w2.active >= 50, `${w2.active} < 50`);
110+
assert.ok(w2.active >= 50 - skew, `${w2.active} < 50 - ${skew}`);
105111
assert.ok(wElu.active >= 50, `${wElu.active} < 50`);
106112
assert.ok(idleActive(wElu) < idleActive(w2),
107113
`${idleActive(wElu)} >= ${idleActive(w2)}`);

0 commit comments

Comments
 (0)