• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4const assert = require('assert');
5const initHooks = require('./init-hooks');
6const { checkInvocations } = require('./hook-checks');
7const TIMEOUT = common.platformTimeout(100);
8
9const hooks = initHooks();
10hooks.enable();
11
12const interval = setInterval(common.mustCall(ontimeout, 2), TIMEOUT);
13const as = hooks.activitiesOfTypes('Timeout');
14assert.strictEqual(as.length, 1);
15const t1 = as[0];
16assert.strictEqual(t1.type, 'Timeout');
17assert.strictEqual(typeof t1.uid, 'number');
18assert.strictEqual(typeof t1.triggerAsyncId, 'number');
19checkInvocations(t1, { init: 1 }, 't1: when timer installed');
20
21let iter = 0;
22function ontimeout() {
23  if (iter === 0) {
24    checkInvocations(t1, { init: 1, before: 1 }, 't1: when first timer fired');
25  } else {
26    checkInvocations(t1, { init: 1, before: 2, after: 1 },
27                     't1: when first interval fired again');
28    clearInterval(interval);
29    return;
30  }
31
32  iter++;
33  throw new Error('setInterval Error');
34}
35
36process.once('uncaughtException', common.mustCall((err) => {
37  assert.strictEqual(err.message, 'setInterval Error');
38}));
39
40process.on('exit', () => {
41  hooks.disable();
42  hooks.sanityCheck('Timeout');
43
44  checkInvocations(t1, { init: 1, before: 2, after: 2, destroy: 1 },
45                   't1: when process exits');
46});
47