This repository has been archived by the owner on Aug 31, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 75
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
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.
- Loading branch information
1 parent
edc403c
commit b17d7b6
Showing
2 changed files
with
56 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,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); | ||
} |