Skip to content

Commit 364bf03

Browse files
Flarnarichardlau
authored andcommitted
test: fix races in test-performance-eventlooputil
Fix two races in test-performance-eventlooputil resulting in a flaky test. elu1 was capture after start time t from spin look. If OS descides to reschedule the process after capturing t but before getting elu for >=50ms the spin loop is actually a nop. elu1 doesn't show this and as a result elut3 = eventLoopUtilization(elu1) results in elu3.active === 0. Moving capturing of t after capturing t, just before the spin look avoids this. Similar if OS decides to shedule a different process between getting the total elu from start and the diff elu showing the spin loop the check to verify that total active time is long then the spin loop fails. Exchanging these statements avoids this race. PR-URL: #36028Fixes: #35309 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 7b0ed4b commit 364bf03

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,28 @@ if (nodeTiming.loopStart === -1){
2323
}
2424

2525
setTimeout(mustCall(functionr(){
26-
constt=Date.now();
2726
constelu1=eventLoopUtilization();
2827

2928
// Force idle time to accumulate before allowing test to continue.
3029
if(elu1.idle<=0)
3130
returnsetTimeout(mustCall(r),5);
3231

32+
constt=Date.now();
3333
while(Date.now()-t<SPIN_DUR){}
3434

35-
constelu2=eventLoopUtilization();
36-
constelu3=eventLoopUtilization(elu1);
37-
constelu4=eventLoopUtilization(elu2,elu1);
35+
constelu2=eventLoopUtilization(elu1);
36+
constelu3=eventLoopUtilization();
37+
constelu4=eventLoopUtilization(elu3,elu1);
3838

39-
assert.strictEqual(elu3.idle,0);
39+
assert.strictEqual(elu2.idle,0);
4040
assert.strictEqual(elu4.idle,0);
41-
assert.strictEqual(elu3.utilization,1);
41+
assert.strictEqual(elu2.utilization,1);
4242
assert.strictEqual(elu4.utilization,1);
43-
assert.strictEqual(elu2.active-elu1.active,elu4.active);
44-
assert.ok(elu3.active>SPIN_DUR-10,`${elu3.active} <= ${SPIN_DUR-10}`);
43+
assert.strictEqual(elu3.active-elu1.active,elu4.active);
44+
assert.ok(elu2.active>SPIN_DUR-10,`${elu2.active} <= ${SPIN_DUR-10}`);
45+
assert.ok(elu2.active<elu4.active,`${elu2.active} >= ${elu4.active}`);
46+
assert.ok(elu3.active>elu2.active,`${elu3.active} <= ${elu2.active}`);
4547
assert.ok(elu3.active>elu4.active,`${elu3.active} <= ${elu4.active}`);
46-
assert.ok(elu2.active>elu3.active,`${elu2.active} <= ${elu3.active}`);
47-
assert.ok(elu2.active>elu4.active,`${elu2.active} <= ${elu4.active}`);
4848

4949
setTimeout(mustCall(runIdleTimeTest),TIMEOUT);
5050
}),5);

0 commit comments

Comments
(0)