Skip to content

Commit 2e3251e

Browse files
Flarnajuanarbol
authored andcommitted
test: correct test-worker-eventlooputil
The active worker check compared the time from sending message till response arrived from worker with the complete time the worker was running till it responses to the spin request. If sending back the message is slow for some reason the test fails. Adapt the test to compare the time seen inside the worker with the time read from main thread. PR-URL: nodejs#35891 Fixes: nodejs#35844 Refs: nodejs#35886 Refs: nodejs#35664 Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Rich Trott <[email protected]> Backport-PR-URL: nodejs#37165
1 parent c5e9544 commit 2e3251e

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

test/parallel/test-worker-eventlooputil.js

+8-10
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ function workerOnMetricsMsg(msg) {
3434
}
3535

3636
if (msg.cmd === 'spin') {
37+
const elu = eventLoopUtilization();
3738
const t = now();
3839
while (now() - t < msg.dur);
39-
return this.postMessage(eventLoopUtilization());
40+
return this.postMessage(eventLoopUtilization(elu));
4041
}
4142
}
4243

@@ -50,12 +51,13 @@ let workerELU;
5051
if (eventLoopUtilization().idle <= 0)
5152
return setTimeout(mustCall(r), 5);
5253

54+
mainElu = eventLoopUtilization();
55+
5356
worker = new Worker(__filename, { argv: [ 'iamalive' ] });
5457
metricsCh = new MessageChannel();
5558
worker.postMessage({ metricsCh: metricsCh.port1 }, [ metricsCh.port1 ]);
5659

5760
workerELU = worker.performance.eventLoopUtilization;
58-
mainElu = eventLoopUtilization();
5961
metricsCh.port2.once('message', mustCall(checkWorkerIdle));
6062
metricsCh.port2.postMessage({ cmd: 'elu' });
6163
// Make sure it's still safe to call eventLoopUtilization() after the worker
@@ -66,15 +68,10 @@ let workerELU;
6668
}));
6769
})();
6870

69-
7071
function checkWorkerIdle(wElu) {
71-
const tmpMainElu = eventLoopUtilization(mainElu);
7272
const perfWorkerElu = workerELU();
73-
const eluDiff = eventLoopUtilization(perfWorkerElu, mainElu);
73+
const tmpMainElu = eventLoopUtilization(mainElu);
7474

75-
assert.strictEqual(idleActive(eluDiff),
76-
(perfWorkerElu.active - mainElu.active) +
77-
(perfWorkerElu.idle - mainElu.idle));
7875
assert.ok(idleActive(wElu) > 0, `${idleActive(wElu)} <= 0`);
7976
assert.ok(idleActive(workerELU(wElu)) > 0,
8077
`${idleActive(workerELU(wElu))} <= 0`);
@@ -104,8 +101,9 @@ function checkWorkerActive() {
104101
const w2 = workerELU(w);
105102

106103
assert.ok(w2.active >= 50, `${w2.active} < 50`);
107-
assert.ok(idleActive(wElu) > idleActive(w2),
108-
`${idleActive(wElu)} <= ${idleActive(w2)}`);
104+
assert.ok(wElu.active >= 50, `${wElu.active} < 50`);
105+
assert.ok(idleActive(wElu) < idleActive(w2),
106+
`${idleActive(wElu)} >= ${idleActive(w2)}`);
109107

110108
metricsCh.port2.postMessage({ cmd: 'close' });
111109
});

0 commit comments

Comments
 (0)