Skip to content

Commit d7a4ccd

Browse files
Flarnarichardlau
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: #35891 Fixes: #35844 Refs: #35886 Refs: #35664 Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Backport-PR-URL: #37165
1 parent eec7542 commit d7a4ccd

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

test/parallel/test-bootstrap-modules.js

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ if (!common.isMainThread) {
9393
expectedModules.add('Internal Binding messaging');
9494
expectedModules.add('Internal Binding symbols');
9595
expectedModules.add('Internal Binding worker');
96+
expectedModules.add('Internal Binding performance');
9697
expectedModules.add('NativeModule _stream_duplex');
9798
expectedModules.add('NativeModule _stream_passthrough');
9899
expectedModules.add('NativeModule _stream_readable');

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)