Skip to content

Commit 52b2270

Browse files
creestorcreestornovemberborn
authored
Cap idle timeouts to the maximum possible value
Co-authored-by: creestor <[email protected]> Co-authored-by: Mark Wubben <[email protected]>
1 parent d84dbc1 commit 52b2270

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

lib/api.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import fork from './fork.js';
1616
import * as globs from './globs.js';
1717
import isCi from './is-ci.js';
1818
import {getApplicableLineNumbers} from './line-numbers.js';
19+
import {setCappedTimeout} from './now-and-timers.cjs';
1920
import {observeWorkerProcess} from './plugin-support/shared-workers.js';
2021
import RunStatus from './run-status.js';
2122
import scheduler from './scheduler.js';
@@ -52,7 +53,7 @@ class TimeoutTrigger {
5253

5354
debounce() {
5455
if (this.timer === undefined) {
55-
this.timer = setTimeout(() => this.trigger(), this.waitMs);
56+
this.timer = setCappedTimeout(() => this.trigger(), this.waitMs);
5657
} else {
5758
this.timer.refresh();
5859
}

lib/now-and-timers.cjs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,14 @@ const timers = require('timers');
33

44
Object.assign(exports, timers);
55
exports.now = Date.now;
6+
7+
// Any delay larger than this value is ignored by Node.js, with a delay of `1`
8+
// used instead. See <https://nodejs.org/api/timers.html#settimeoutcallback-delay-args>.
9+
const MAX_DELAY = (2 ** 31) - 1;
10+
11+
function setCappedTimeout(callback, delay) {
12+
const safeDelay = Math.min(delay, MAX_DELAY);
13+
return timers.setTimeout(callback, safeDelay);
14+
}
15+
16+
exports.setCappedTimeout = setCappedTimeout;

lib/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ export default class Test {
405405

406406
this.clearTimeout();
407407
this.timeoutMs = ms;
408-
this.timeoutTimer = nowAndTimers.setTimeout(() => {
408+
this.timeoutTimer = nowAndTimers.setCappedTimeout(() => {
409409
this.saveFirstError(new Error(message || 'Test timeout exceeded'));
410410

411411
if (this.finishDueToTimeout) {

0 commit comments

Comments
 (0)