Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v12.22.0 proposal #37797

Merged
merged 17 commits into from
Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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 <[email protected]>
Reviewed-By: Rich Trott <[email protected]>

Backport-PR-URL: #37165
  • Loading branch information
Flarna authored and richardlau committed Mar 16, 2021
commit d7a4ccdf098f3a4f233d1c514fff0db3ddf0285a
1 change: 1 addition & 0 deletions test/parallel/test-bootstrap-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ if (!common.isMainThread) {
expectedModules.add('Internal Binding messaging');
expectedModules.add('Internal Binding symbols');
expectedModules.add('Internal Binding worker');
expectedModules.add('Internal Binding performance');
expectedModules.add('NativeModule _stream_duplex');
expectedModules.add('NativeModule _stream_passthrough');
expectedModules.add('NativeModule _stream_readable');
Expand Down
18 changes: 8 additions & 10 deletions test/parallel/test-worker-eventlooputil.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ function workerOnMetricsMsg(msg) {
}

if (msg.cmd === 'spin') {
const elu = eventLoopUtilization();
const t = now();
while (now() - t < msg.dur);
return this.postMessage(eventLoopUtilization());
return this.postMessage(eventLoopUtilization(elu));
}
}

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

mainElu = eventLoopUtilization();

worker = new Worker(__filename, { argv: [ 'iamalive' ] });
metricsCh = new MessageChannel();
worker.postMessage({ metricsCh: metricsCh.port1 }, [ metricsCh.port1 ]);

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


function checkWorkerIdle(wElu) {
const tmpMainElu = eventLoopUtilization(mainElu);
const perfWorkerElu = workerELU();
const eluDiff = eventLoopUtilization(perfWorkerElu, mainElu);
const tmpMainElu = eventLoopUtilization(mainElu);

assert.strictEqual(idleActive(eluDiff),
(perfWorkerElu.active - mainElu.active) +
(perfWorkerElu.idle - mainElu.idle));
assert.ok(idleActive(wElu) > 0, `${idleActive(wElu)} <= 0`);
assert.ok(idleActive(workerELU(wElu)) > 0,
`${idleActive(workerELU(wElu))} <= 0`);
Expand Down Expand Up @@ -104,8 +101,9 @@ function checkWorkerActive() {
const w2 = workerELU(w);

assert.ok(w2.active >= 50, `${w2.active} < 50`);
assert.ok(idleActive(wElu) > idleActive(w2),
`${idleActive(wElu)} <= ${idleActive(w2)}`);
assert.ok(wElu.active >= 50, `${wElu.active} < 50`);
assert.ok(idleActive(wElu) < idleActive(w2),
`${idleActive(wElu)} >= ${idleActive(w2)}`);

metricsCh.port2.postMessage({ cmd: 'close' });
});
Expand Down