Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 #30787 that returns the test to the state it
had originally.
  • Loading branch information
benjamingr committed Jan 27, 2022
commit 2032f2d6f71104cfc80d26854b9b6d2ac6410a4d
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