summaryrefslogtreecommitdiff
path: root/test/parallel/test-timers-unrefd-interval-still-fires.js
blob: bf16013f0049650c57b5a56dc78ed77fbd5f3c8b (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
'use strict';
/*
 * This test is a regression test for joyent/node#8900.
 */
const common = require('../common');

const TEST_DURATION = common.platformTimeout(1000);
const N = 3;
let nbIntervalFired = 0;

const keepOpen = setTimeout(() => {
  console.error('[FAIL] Interval fired %d/%d times.', nbIntervalFired, N);
  throw new Error('Test timed out. keepOpen was not canceled.');
}, TEST_DURATION);

const timer = setInterval(() => {
  ++nbIntervalFired;
  if (nbIntervalFired === N) {
    clearInterval(timer);
    timer._onTimeout = () => {
      throw new Error('Unrefd interval fired after being cleared.');
    };
    clearTimeout(keepOpen);
  }
}, 1);

timer.unref();