summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGerhard Stoebich <18708370+Flarna@users.noreply.github.com>2020-10-31 01:07:39 +0100
committerRichard Lau <rlau@redhat.com>2021-03-16 00:04:18 +0000
commitd7a4ccdf098f3a4f233d1c514fff0db3ddf0285a (patch)
treed12779c672dc959ce72c5a343a5c2503ab7a781d
parenteec75427811cd80ee0818b16d51ffd2a9a4e113b (diff)
downloadnode-new-d7a4ccdf098f3a4f233d1c514fff0db3ddf0285a.tar.gz
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: https://github.com/nodejs/node/pull/35891 Fixes: https://github.com/nodejs/node/issues/35844 Refs: https://github.com/nodejs/node/pull/35886 Refs: https://github.com/nodejs/node/pull/35664 Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Backport-PR-URL: https://github.com/nodejs/node/pull/37165
-rw-r--r--test/parallel/test-bootstrap-modules.js1
-rw-r--r--test/parallel/test-worker-eventlooputil.js18
2 files changed, 9 insertions, 10 deletions
diff --git a/test/parallel/test-bootstrap-modules.js b/test/parallel/test-bootstrap-modules.js
index e6bf26ee0a..e978edf04f 100644
--- a/test/parallel/test-bootstrap-modules.js
+++ b/test/parallel/test-bootstrap-modules.js
@@ -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');
diff --git a/test/parallel/test-worker-eventlooputil.js b/test/parallel/test-worker-eventlooputil.js
index 6759bd362c..7e012cb2b0 100644
--- a/test/parallel/test-worker-eventlooputil.js
+++ b/test/parallel/test-worker-eventlooputil.js
@@ -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));
}
}
@@ -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
@@ -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`);
@@ -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' });
});