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.lookupService('127.0.0.1', 80, common.mustCall(onlookupService)); 17function onlookupService() { 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('GETNAMEINFOREQWRAP'); 22 assert.strictEqual(as.length, 1); 23 24 const a = as[0]; 25 assert.strictEqual(a.type, 'GETNAMEINFOREQWRAP'); 26 assert.strictEqual(typeof a.uid, 'number'); 27 assert.strictEqual(a.triggerAsyncId, 1); 28 checkInvocations(a, { init: 1, before: 1 }, 29 'while in onlookupService callback'); 30 tick(2); 31} 32 33process.on('exit', onexit); 34 35function onexit() { 36 hooks.disable(); 37 hooks.sanityCheck('GETNAMEINFOREQWRAP'); 38 39 const as = hooks.activitiesOfTypes('GETNAMEINFOREQWRAP'); 40 const a = as[0]; 41 checkInvocations(a, { init: 1, before: 1, after: 1, destroy: 1 }, 42 'when process exits'); 43} 44