mirror of
https://github.com/nodejs/node.git
synced 2026-11-29 14:27:57 -05:00
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>
This commit is contained in:
1 parent
7c62da0585
commit
462946a5fa
1 file changed
+8
-7
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user