1'use strict'; 2const common = require('../../common'); 3const assert = require('assert'); 4const async_hooks = require('async_hooks'); 5const test_async = require(`./build/${common.buildType}/test_async`); 6 7const events = []; 8let testId; 9const initAsyncId = async_hooks.executionAsyncId(); 10 11async_hooks.createHook({ 12 init(id, provider, triggerAsyncId, resource) { 13 if (provider === 'TestResource') { 14 testId = id; 15 events.push({ type: 'init', id, provider, triggerAsyncId, resource }); 16 } 17 }, 18 before(id) { 19 if (testId === id) { 20 events.push({ type: 'before', id }); 21 } 22 }, 23 after(id) { 24 if (testId === id) { 25 events.push({ type: 'after', id }); 26 } 27 }, 28 destroy(id) { 29 if (testId === id) { 30 events.push({ type: 'destroy', id }); 31 } 32 } 33}).enable(); 34 35const resource = { foo: 'foo' }; 36 37events.push({ type: 'start' }); 38test_async.Test(5, resource, common.mustCall(function(err, val) { 39 assert.strictEqual(err, null); 40 assert.strictEqual(val, 10); 41 events.push({ type: 'complete' }); 42 process.nextTick(common.mustCall()); 43})); 44events.push({ type: 'scheduled' }); 45 46process.on('exit', () => { 47 assert.deepStrictEqual(events, [ 48 { type: 'start' }, 49 { type: 'init', 50 id: testId, 51 provider: 'TestResource', 52 triggerAsyncId: initAsyncId, 53 resource }, 54 { type: 'scheduled' }, 55 { type: 'before', id: testId }, 56 { type: 'complete' }, 57 { type: 'after', id: testId }, 58 { type: 'destroy', id: testId }, 59 ]); 60}); 61