Skip to content

Commit 969201a

Browse files
committed
lib: test_runner#mock:timers respeced timeout_max behaviour
1 parent 5a3da7b commit 969201a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/internal/test_runner/mock/mock_timers.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ let kResistStopPropagation;
4848
let kMock;
4949
// Initial epoch to which #now should be set to
5050
const kInitialEpoch = 0;
51+
/** @see lib/internal/timers.js#TIMEOUT_MAX */
52+
const TIMEOUT_MAX = 2 ** 31 - 1;
5153

5254
function compareTimersLists(a, b) {
5355
return (a.runAt - b.runAt) || (a.id - b.id);
@@ -288,6 +290,10 @@ class MockTimers {
288290
}
289291

290292
#createTimer(isInterval, callback, delay, ...args) {
293+
if (delay > TIMEOUT_MAX) {
294+
delay = 1;
295+
}
296+
291297
const timerId = this.#currentTimer++;
292298
const opts = {
293299
__proto__: null,
@@ -297,7 +303,7 @@ class MockTimers {
297303
interval: isInterval ? delay : undefined,
298304
args,
299305
};
300-
306+
301307
const timer = new Timeout(opts);
302308
this.#executionQueue.insert(timer);
303309
return timer;

0 commit comments

Comments
 (0)