Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cap idle timeouts to the maximum possible value #3100

Merged
merged 3 commits into from Sep 5, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/api.js
Expand Up @@ -19,6 +19,7 @@ import {getApplicableLineNumbers} from './line-numbers.js';
import {observeWorkerProcess} from './plugin-support/shared-workers.js';
import RunStatus from './run-status.js';
import scheduler from './scheduler.js';
import nowAndTimers from './now-and-timers.cjs';
import serializeError from './serialize-error.js';

function resolveModules(modules) {
Expand Down Expand Up @@ -52,7 +53,7 @@ class TimeoutTrigger {

debounce() {
if (this.timer === undefined) {
this.timer = setTimeout(() => this.trigger(), this.waitMs);
this.timer = nowAndTimers.setSafeTimeout(() => this.trigger(), this.waitMs);
} else {
this.timer.refresh();
}
Expand Down
11 changes: 10 additions & 1 deletion lib/now-and-timers.cjs
@@ -1,5 +1,14 @@
'use strict';
const timers = require('timers');

Object.assign(exports, timers);
// Slightly higher than 24 days
const MAX_INT32 = Math.pow(2, 31) - 1;

const setSafeTimeout = (callback, ms) => {
const avaliableMs = ms < MAX_INT32 ? ms : MAX_INT32;
creestor marked this conversation as resolved.
Show resolved Hide resolved

return timers.setTimeout(callback, avaliableMs)
}

Object.assign(exports, timers, { setSafeTimeout });
creestor marked this conversation as resolved.
Show resolved Hide resolved
exports.now = Date.now;
2 changes: 1 addition & 1 deletion lib/test.js
Expand Up @@ -405,7 +405,7 @@ export default class Test {

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

if (this.finishDueToTimeout) {
Expand Down