summaryrefslogtreecommitdiff
path: root/test/parallel/test-timers-max-duration-warning.js
blob: c978cf29c3fe4d4a2e22e7238c7710a755663331 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
'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() {
  assert.fail('Timer should be canceled');
}

process.on('warning', common.mustCall((warning) => {
  if (warning.name === 'DeprecationWarning') return;

  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);
}, 5));


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