1'use strict'; 2// Flags: --expose_gc 3 4// This test ensures that userland-only AsyncResources cause a destroy event to 5// be emitted when they get gced. 6 7const common = require('../common'); 8const assert = require('assert'); 9const async_hooks = require('async_hooks'); 10 11const destroyedIds = new Set(); 12async_hooks.createHook({ 13 destroy: common.mustCallAtLeast((asyncId) => { 14 destroyedIds.add(asyncId); 15 }, 1) 16}).enable(); 17 18let asyncId = null; 19{ 20 const res = new async_hooks.AsyncResource('foobar'); 21 asyncId = res.asyncId(); 22} 23 24setImmediate(() => { 25 global.gc(); 26 setImmediate(() => assert.ok(destroyedIds.has(asyncId))); 27}); 28