Commit fd204481115 for nodejs
commit fd204481115fe32277beb86ccc726976deb61f79
Author: Matteo Collina <hello@matteocollina.com>
Date: Wed Oct 21 21:26:20 2026 -0700
test: keep objects alive in finalization fixtures
process.finalization only holds weak references to registered objects.
In unregister-function.mjs and finalization-cleanup.mjs the registered
objects were not captured by any closure, so a GC before exit could
collect them, skipping their exit callbacks and failing the assertions.
Reference them from the exit listeners so they stay reachable.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011DQrzezHzwzfCYeh2cYm2U
Signed-off-by: Matteo Collina <hello@matteocollina.com>
PR-URL: https://github.com/nodejs/node/pull/66869
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
diff --git a/test/fixtures/process/finalization-cleanup.mjs b/test/fixtures/process/finalization-cleanup.mjs
index 88d6c17cc7e..8b7705b64d6 100644
--- a/test/fixtures/process/finalization-cleanup.mjs
+++ b/test/fixtures/process/finalization-cleanup.mjs
@@ -30,5 +30,7 @@ for (let i = 0; i < 10; i++) {
}
process.on('exit', function () {
+ // Keep `first` and `third` alive until exit; registrations only hold them weakly.
+ deepStrictEqual(keptAlive.map((obj) => obj.name), ['first', 'third'])
deepStrictEqual(finalized, ['first', 'third'])
})
diff --git a/test/fixtures/process/unregister-function.mjs b/test/fixtures/process/unregister-function.mjs
index b74a5b8203a..01f704e4fa1 100644
--- a/test/fixtures/process/unregister-function.mjs
+++ b/test/fixtures/process/unregister-function.mjs
@@ -25,5 +25,8 @@ unregisterABeforeExit()
unregisterBAgain()
process.on('exit', function () {
+ // Keep `a` and `b` alive until exit; registrations only hold them weakly.
+ strictEqual(a.name, 'a')
+ strictEqual(b.name, 'b')
strictEqual(calls.join(','), 'b:exit')
})