0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-timers-max-duration-warning.js
Jeremiah Senkpiel ce3586da31 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>
2017-09-29 08:45:06 -07:00

41 lines
917 B
JavaScript

'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);
}