-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
timers: warn on overflowed timeout duration
Cherry-pick from ayo Ayo commit log: > Previously there wasn't any clear indicator when you hit the overflow > other than possibly unexpected behavior, and I think emitting a warning > may be appropriate. > PR-URL: ayojs/ayo#71 > Reviewed-By: Scott Trinh <[email protected]> > Reviewed-By: Alexey Orlenko <[email protected]> > Reviewed-By: Stephen Belanger <[email protected]> > Reviewed-By: Anna Henningsen <[email protected]> > Reviewed-By: Benjamin Gruenbaum <[email protected]> PR-URL: #15627 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
- Loading branch information
1 parent
347b6fc
commit 6af6964
Showing
2 changed files
with
59 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const timers = require('timers'); | ||
|
||
const OVERFLOW = Math.pow(2, 31); // TIMEOUT_MAX is 2^31-1 | ||
|
||
function timerNotCanceled() { | ||
common.fail('Timer should be canceled'); | ||
} | ||
|
||
process.on('warning', common.mustCall((warning) => { | ||
const lines = warning.message.split('\n'); | ||
|
||
assert.strictEqual(warning.name, 'TimeoutOverflowWarning'); | ||
assert.strictEqual(lines[0], `${OVERFLOW} does not fit into a 32-bit signed` + | ||
' integer.'); | ||
assert.strictEqual(lines.length, 2); | ||
}, 3)); | ||
|
||
|
||
{ | ||
const timeout = setTimeout(timerNotCanceled, OVERFLOW); | ||
clearTimeout(timeout); | ||
} | ||
|
||
{ | ||
const interval = setInterval(timerNotCanceled, OVERFLOW); | ||
clearInterval(interval); | ||
} | ||
|
||
{ | ||
const timer = { | ||
_onTimeout: timerNotCanceled | ||
}; | ||
timers.enroll(timer, OVERFLOW); | ||
timers.active(timer); | ||
timers.unenroll(timer); | ||
} |