summaryrefslogtreecommitdiff
path: root/test/async-hooks/test-graph.timeouts.js
blob: 2ec1420f0c03b1515c67f86af499a8a054e1e0c7 (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
'use strict';

const common = require('../common');
const initHooks = require('./init-hooks');
const verifyGraph = require('./verify-graph');
const TIMEOUT = 1;

const hooks = initHooks();
hooks.enable();

setTimeout(common.mustCall(ontimeout), TIMEOUT);
function ontimeout() {
  setTimeout(onsecondTimeout, TIMEOUT + 1);
}

function onsecondTimeout() {
  setTimeout(onthirdTimeout, TIMEOUT + 2);
}

function onthirdTimeout() {}

process.on('exit', onexit);

function onexit() {
  hooks.disable();
  verifyGraph(
    hooks,
    [ { type: 'Timeout', id: 'timeout:1', triggerAsyncId: null },
      { type: 'Timeout', id: 'timeout:2', triggerAsyncId: 'timeout:1' },
      { type: 'Timeout', id: 'timeout:3', triggerAsyncId: 'timeout:2' }]
  );
}