Skip to content

Commit

Permalink
Cap idle timeouts to the maximum possible value
Browse files Browse the repository at this point in the history
Co-authored-by: creestor <[email protected]>
Co-authored-by: Mark Wubben <[email protected]>
  • Loading branch information
3 people authored Sep 5, 2022
1 parent d84dbc1 commit 52b2270
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import fork from './fork.js';
import * as globs from './globs.js';
import isCi from './is-ci.js';
import {getApplicableLineNumbers} from './line-numbers.js';
import {setCappedTimeout} from './now-and-timers.cjs';
import {observeWorkerProcess} from './plugin-support/shared-workers.js';
import RunStatus from './run-status.js';
import scheduler from './scheduler.js';
Expand Down Expand Up @@ -52,7 +53,7 @@ class TimeoutTrigger {

debounce() {
if (this.timer === undefined) {
this.timer = setTimeout(() => this.trigger(), this.waitMs);
this.timer = setCappedTimeout(() => this.trigger(), this.waitMs);
} else {
this.timer.refresh();
}
Expand Down
11 changes: 11 additions & 0 deletions lib/now-and-timers.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,14 @@ const timers = require('timers');

Object.assign(exports, timers);
exports.now = Date.now;

// Any delay larger than this value is ignored by Node.js, with a delay of `1`
// used instead. See <https://nodejs.org/api/timers.html#settimeoutcallback-delay-args>.
const MAX_DELAY = (2 ** 31) - 1;

function setCappedTimeout(callback, delay) {
const safeDelay = Math.min(delay, MAX_DELAY);
return timers.setTimeout(callback, safeDelay);
}

exports.setCappedTimeout = setCappedTimeout;
2 changes: 1 addition & 1 deletion lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ export default class Test {

this.clearTimeout();
this.timeoutMs = ms;
this.timeoutTimer = nowAndTimers.setTimeout(() => {
this.timeoutTimer = nowAndTimers.setCappedTimeout(() => {
this.saveFirstError(new Error(message || 'Test timeout exceeded'));

if (this.finishDueToTimeout) {
Expand Down

0 comments on commit 52b2270

Please sign in to comment.