From c759d65ba522fb16c09b7968ccea79e999d9886a Mon Sep 17 00:00:00 2001 From: Andrey Pechkurov Date: Wed, 26 Feb 2020 09:38:48 +0300 Subject: [PATCH] test: add GC test for disabled AsyncLocalStorage PR-URL: https://github.com/nodejs/node/pull/31995 Reviewed-By: Anna Henningsen Reviewed-By: Gireesh Punathil Reviewed-By: Stephen Belanger Reviewed-By: Vladimir de Turckheim Reviewed-By: James M Snell Reviewed-By: Michael Dawson --- .../test-async-local-storage-gcable.js | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 test/async-hooks/test-async-local-storage-gcable.js diff --git a/test/async-hooks/test-async-local-storage-gcable.js b/test/async-hooks/test-async-local-storage-gcable.js new file mode 100644 index 00000000000000..37b04b38d14588 --- /dev/null +++ b/test/async-hooks/test-async-local-storage-gcable.js @@ -0,0 +1,20 @@ +'use strict'; +// Flags: --expose_gc + +// 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 onGC = require('../common/ongc'); + +let asyncLocalStorage = new AsyncLocalStorage(); + +asyncLocalStorage.runSyncAndReturn({}, () => { + asyncLocalStorage.disable(); + + onGC(asyncLocalStorage, { ongc: common.mustCall() }); +}); + +asyncLocalStorage = null; +global.gc();