1'use strict'; 2const common = require('../common'); 3const assert = require('assert'); 4const async_hooks = require('async_hooks'); 5 6// This test ensures that fast-path PromiseHook assigns async ids 7// to already created promises when the native hook function is 8// triggered on before event. 9 10let initialAsyncId; 11const promise = new Promise((resolve) => { 12 setTimeout(() => { 13 initialAsyncId = async_hooks.executionAsyncId(); 14 async_hooks.createHook({ 15 after: common.mustCall(() => {}, 2) 16 }).enable(); 17 resolve(); 18 }, 0); 19}); 20 21promise.then(common.mustCall(() => { 22 const id = async_hooks.executionAsyncId(); 23 assert.notStrictEqual(id, initialAsyncId); 24 assert.ok(id > 0); 25})); 26