diff options
author | Jeremiah Senkpiel <fishrock123@rocketmail.com> | 2016-05-24 16:39:54 -0400 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2017-09-29 08:45:06 -0700 |
commit | ce3586da31499112c66be6a520c4ca2209d03aba (patch) | |
tree | 52920d93347cd1e4613a9cf675d09896380a02b3 /test/parallel/test-timers-max-duration-warning.js | |
parent | 4843c2f41571088b16e673c1f996bc361ab526a6 (diff) | |
download | android-node-v8-ce3586da31499112c66be6a520c4ca2209d03aba.tar.gz android-node-v8-ce3586da31499112c66be6a520c4ca2209d03aba.tar.bz2 android-node-v8-ce3586da31499112c66be6a520c4ca2209d03aba.zip |
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: https://github.com/ayojs/ayo/pull/71
> Reviewed-By: Scott Trinh <scott@scotttrinh.com>
> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
> Reviewed-By: Anna Henningsen <anna@addaleax.net>
> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/15627
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'test/parallel/test-timers-max-duration-warning.js')
-rw-r--r-- | test/parallel/test-timers-max-duration-warning.js | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/test/parallel/test-timers-max-duration-warning.js b/test/parallel/test-timers-max-duration-warning.js new file mode 100644 index 0000000000..b352b745c5 --- /dev/null +++ b/test/parallel/test-timers-max-duration-warning.js @@ -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); +} |