• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4const assert = require('assert');
5const tick = require('../common/tick');
6const initHooks = require('./init-hooks');
7const { checkInvocations } = require('./hook-checks');
8const dns = require('dns');
9
10if (!common.isMainThread)
11  common.skip('Worker bootstrapping works differently -> different async IDs');
12
13const hooks = initHooks();
14
15hooks.enable();
16dns.lookup('www.google.com', 4, common.mustCall(onlookup));
17function onlookup() {
18  // We don't care about the error here in order to allow
19  // tests to run offline (lookup will fail in that case and the err be set);
20
21  const as = hooks.activitiesOfTypes('GETADDRINFOREQWRAP');
22  assert.strictEqual(as.length, 1);
23
24  const a = as[0];
25  assert.strictEqual(a.type, 'GETADDRINFOREQWRAP');
26  assert.strictEqual(typeof a.uid, 'number');
27  assert.strictEqual(a.triggerAsyncId, 1);
28  checkInvocations(a, { init: 1, before: 1 }, 'while in onlookup callback');
29  tick(2);
30}
31
32process.on('exit', onexit);
33
34function onexit() {
35  hooks.disable();
36  hooks.sanityCheck('GETADDRINFOREQWRAP');
37
38  const as = hooks.activitiesOfTypes('GETADDRINFOREQWRAP');
39  const a = as[0];
40  checkInvocations(a, { init: 1, before: 1, after: 1, destroy: 1 },
41                   'when process exits');
42}
43