Commit 26bcd1e3e92 for nodejs
commit 26bcd1e3e925e6b45133f18c91c790252a8b4d99
Author: Filip Skokan <panva.ip@gmail.com>
Date: Tue Sep 22 11:25:52 2026 +0200
test: deflake pummel/test-timers
Timers may fire late on busy systems. Remove the upper timing bounds
while retaining the lower bounds, and use performance.now() to measure
elapsed time without wall-clock adjustments.
Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Assisted-by: Codex
PR-URL: https://github.com/nodejs/node/pull/66135
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
diff --git a/test/pummel/test-timers.js b/test/pummel/test-timers.js
index b51c395d53d..83127ce955b 100644
--- a/test/pummel/test-timers.js
+++ b/test/pummel/test-timers.js
@@ -23,20 +23,21 @@
const common = require('../common');
const assert = require('assert');
-const WINDOW = 200; // Why does this need to be so big?
+// Timers may fire late on busy systems, so only enforce a lower bound.
+const WINDOW = 200;
{
- const starttime = Date.now();
+ const starttime = performance.now();
setTimeout(common.mustCall(function() {
- const endtime = Date.now();
+ const endtime = performance.now();
const diff = endtime - starttime;
assert.ok(diff > 0);
console.error(`diff: ${diff}`);
- assert.ok(Math.abs(diff - 1000) < WINDOW);
+ assert.ok(diff > 1000 - WINDOW);
}), 1000);
}
@@ -47,13 +48,13 @@ const WINDOW = 200; // Why does this need to be so big?
}
{
- const starttime = Date.now();
+ const starttime = performance.now();
let interval_count = 0;
setInterval(common.mustCall(function() {
interval_count += 1;
- const endtime = Date.now();
+ const endtime = performance.now();
const diff = endtime - starttime;
assert.ok(diff > 0);
@@ -61,7 +62,7 @@ const WINDOW = 200; // Why does this need to be so big?
const t = interval_count * 1000;
- assert.ok(Math.abs(diff - t) < WINDOW * interval_count);
+ assert.ok(diff > t - WINDOW * interval_count);
assert.ok(interval_count <= 3, `interval_count: ${interval_count}`);
if (interval_count === 3)