node/test/async-hooks/test-async-local-storage-gcable.js
Antoine du Hamel bfc81ca228
test: ensure assertions are reachable in test/async-hooks
PR-URL: https://github.com/nodejs/node/pull/60150
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
2025-10-09 21:57:24 +00:00

28 lines
821 B
JavaScript

'use strict';
// Flags: --expose_gc --expose-internals
// This test ensures that AsyncLocalStorage gets gced once it was disabled
// and no strong references remain in userland.
const common = require('../common');
const { AsyncLocalStorage } = require('async_hooks');
const AsyncContextFrame = require('internal/async_context_frame');
const { onGC } = require('../common/gc');
let asyncLocalStorage = new AsyncLocalStorage();
asyncLocalStorage.run({}, common.mustCall(() => {
asyncLocalStorage.disable();
onGC(asyncLocalStorage, { ongc: common.mustCall() });
}));
if (AsyncContextFrame.enabled) {
// This disable() is needed to remove reference form AsyncContextFrame
// created during exit of run() to the AsyncLocalStore instance.
asyncLocalStorage.disable();
}
asyncLocalStorage = null;
global.gc();