| 19 | module.exports = common.runTest(test); |
| 20 | |
| 21 | function installAsyncHooksForTest () { |
| 22 | return new Promise((resolve, reject) => { |
| 23 | let id; |
| 24 | const events = []; |
| 25 | /** |
| 26 | * TODO(legendecas): investigate why resolving & disabling hooks in |
| 27 | * destroy callback causing crash with case 'callbackscope.js'. |
| 28 | */ |
| 29 | let destroyed = false; |
| 30 | const interval = setInterval(() => { |
| 31 | if (destroyed) { |
| 32 | hook.disable(); |
| 33 | clearInterval(interval); |
| 34 | resolve(events); |
| 35 | } |
| 36 | }, 10); |
| 37 | |
| 38 | const hook = asyncHooks.createHook({ |
| 39 | init (asyncId, type, triggerAsyncId, resource) { |
| 40 | if (id === undefined && type === 'TestResource') { |
| 41 | id = asyncId; |
| 42 | events.push({ eventName: 'init', type, triggerAsyncId, resource }); |
| 43 | } |
| 44 | }, |
| 45 | before (asyncId) { |
| 46 | if (asyncId === id) { |
| 47 | events.push({ eventName: 'before' }); |
| 48 | } |
| 49 | }, |
| 50 | after (asyncId) { |
| 51 | if (asyncId === id) { |
| 52 | events.push({ eventName: 'after' }); |
| 53 | } |
| 54 | }, |
| 55 | destroy (asyncId) { |
| 56 | if (asyncId === id) { |
| 57 | events.push({ eventName: 'destroy' }); |
| 58 | destroyed = true; |
| 59 | } |
| 60 | } |
| 61 | }).enable(); |
| 62 | }); |
| 63 | } |
| 64 | |
| 65 | async function test (binding) { |
| 66 | const libUvThreadCount = Number(process.env.UV_THREADPOOL_SIZE || 4); |