-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Perviously 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: #6956
- Loading branch information
1 parent
fba271b
commit 0367986
Showing
2 changed files
with
52 additions
and
0 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,39 @@ | ||
'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); | ||
} |