Skip to content

Commit 231af88

Browse files
Flarnatargos
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: #35891Fixes: #35844 Refs: #35886 Refs: #35664 Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent 76ebae4 commit 231af88

1 file changed

Lines changed: 8 additions & 10 deletions

File tree

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ function workerOnMetricsMsg(msg) {
3434
}
3535

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

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

54+
mainElu=eventLoopUtilization();
55+
5356
worker=newWorker(__filename,{argv: ['iamalive']});
5457
metricsCh=newMessageChannel();
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
functioncheckWorkerIdle(wElu){
71-
consttmpMainElu=eventLoopUtilization(mainElu);
7272
constperfWorkerElu=workerELU();
73-
consteluDiff=eventLoopUtilization(perfWorkerElu,mainElu);
73+
consttmpMainElu=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
constw2=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)