Skip to content

Commit

Permalink
test: stabilize eventloopdelay test
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
benjamingr committed Jan 27, 2022
1 parent ccb8aae commit 2032f2d
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions test/sequential/test-performance-eventloopdelay.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const assert = require('assert');
const {
monitorEventLoopDelay
} = require('perf_hooks');
const { sleep } = require('internal/util');

{
const histogram = monitorEventLoopDelay();
Expand Down Expand Up @@ -50,12 +49,19 @@ const { sleep } = require('internal/util');
});
}

// Can't use `sleep` from internal/util because it doesn't do a busy wait
// which means we can get 0 values in the histogram sometimes.
function busySleep(ms) {
const target = Date.now() + ms;
while (Date.now() < target) {}
}

{
const histogram = monitorEventLoopDelay({ resolution: 1 });
histogram.enable();
let m = 5;
function spinAWhile() {
sleep(1000);
busySleep(1000);
if (--m > 0) {
setTimeout(spinAWhile, common.platformTimeout(500));
} else {
Expand Down

0 comments on commit 2032f2d

Please sign in to comment.