Skip to content

Commit 2032f2d

Browse files
committed
test: stabilize eventloopdelay test
This change makes the eventloopdelay test less flakey on some platforms by replacing a blocking-wait with a busy-wait which means the eventloop will always be positive increase. This is a partial revert of nodejs#30787 that returns the test to the state it had originally.
1 parent ccb8aae commit 2032f2d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

test/sequential/test-performance-eventloopdelay.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const assert = require('assert');
66
const {
77
monitorEventLoopDelay
88
} = require('perf_hooks');
9-
const { sleep } = require('internal/util');
109

1110
{
1211
const histogram = monitorEventLoopDelay();
@@ -50,12 +49,19 @@ const { sleep } = require('internal/util');
5049
});
5150
}
5251

52+
// Can't use `sleep` from internal/util because it doesn't do a busy wait
53+
// which means we can get 0 values in the histogram sometimes.
54+
function busySleep(ms) {
55+
const target = Date.now() + ms;
56+
while (Date.now() < target) {}
57+
}
58+
5359
{
5460
const histogram = monitorEventLoopDelay({ resolution: 1 });
5561
histogram.enable();
5662
let m = 5;
5763
function spinAWhile() {
58-
sleep(1000);
64+
busySleep(1000);
5965
if (--m > 0) {
6066
setTimeout(spinAWhile, common.platformTimeout(500));
6167
} else {

0 commit comments

Comments
 (0)