1'use strict'; 2 3const common = require('../common'); 4if (!common.hasCrypto) 5 common.skip('missing crypto'); 6if (!common.isMainThread) 7 common.skip('Worker bootstrapping works differently -> different async IDs'); 8 9const assert = require('assert'); 10const tick = require('../common/tick'); 11const initHooks = require('./init-hooks'); 12const { checkInvocations } = require('./hook-checks'); 13const crypto = require('crypto'); 14 15 16const hooks = initHooks(); 17 18hooks.enable(); 19 20crypto.pbkdf2('password', 'salt', 1, 20, 'sha256', common.mustCall(onpbkdf2)); 21 22function onpbkdf2() { 23 const as = hooks.activitiesOfTypes('PBKDF2REQUEST'); 24 const a = as[0]; 25 checkInvocations(a, { init: 1, before: 1 }, 'while in onpbkdf2 callback'); 26 tick(2); 27} 28 29process.on('exit', onexit); 30function onexit() { 31 hooks.disable(); 32 hooks.sanityCheck('PBKDF2REQUEST'); 33 34 const as = hooks.activitiesOfTypes('PBKDF2REQUEST'); 35 assert.strictEqual(as.length, 1); 36 37 const a = as[0]; 38 assert.strictEqual(a.type, 'PBKDF2REQUEST'); 39 assert.strictEqual(typeof a.uid, 'number'); 40 assert.strictEqual(a.triggerAsyncId, 1); 41 checkInvocations(a, { init: 1, before: 1, after: 1, destroy: 1 }, 42 'when process exits'); 43} 44