The close fixture expects the registered object to still be reachable when the process emits exit. Keep a strong reference outside setup() so the assertion does not depend on platform-specific GC timing. Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com> Assisted-by: openai:gpt-5.5 PR-URL: https://github.com/nodejs/node/pull/64085 Refs: https://github.com/nodejs/reliability/issues?q=%22test-process-finalization%22 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day> Reviewed-By: Stefan Stojanovic <stefan.stojanovic@janeasystems.com>
21 lines
359 B
JavaScript
21 lines
359 B
JavaScript
import { strictEqual } from 'assert'
|
|
|
|
let obj
|
|
|
|
function setup() {
|
|
obj = { foo: 'bar' }
|
|
process.finalization.register(obj, shutdown)
|
|
}
|
|
|
|
let shutdownCalled = false
|
|
function shutdown(obj) {
|
|
shutdownCalled = true
|
|
strictEqual(obj.foo, 'bar')
|
|
}
|
|
|
|
setup()
|
|
|
|
process.on('exit', function () {
|
|
strictEqual(obj.foo, 'bar')
|
|
strictEqual(shutdownCalled, true)
|
|
})
|