• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2// Flags: --expose-gc
3
4const common = require('../common');
5const assert = require('assert');
6const tick = require('../common/tick');
7const initHooks = require('./init-hooks');
8const { checkInvocations } = require('./hook-checks');
9const dns = require('dns');
10
11const hooks = initHooks();
12
13hooks.enable();
14// Uses cares for queryA which in turn uses QUERYWRAP
15dns.resolve('localhost', common.mustCall(onresolved));
16
17function onresolved() {
18  const as = hooks.activitiesOfTypes('QUERYWRAP');
19  const a = as[0];
20  assert.strictEqual(as.length, 1);
21  checkInvocations(a, { init: 1, before: 1 }, 'while in onresolved callback');
22  tick(1E4);
23}
24
25process.on('exit', onexit);
26
27function onexit() {
28  hooks.disable();
29  hooks.sanityCheck('QUERYWRAP');
30
31  const as = hooks.activitiesOfTypes('QUERYWRAP');
32  assert.strictEqual(as.length, 1);
33  const a = as[0];
34
35  assert.strictEqual(a.type, 'QUERYWRAP');
36  assert.strictEqual(typeof a.uid, 'number');
37  assert.strictEqual(typeof a.triggerAsyncId, 'number');
38  checkInvocations(a, { init: 1, before: 1, after: 1, destroy: 1 },
39                   'when process exits');
40}
41