Skip to content

Commit fc775f0

Browse files
committed
test: keep finalization ref alive until exit
Keep the registered finalization object strongly reachable until process exit so the test does not depend on GC timing. Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com> Assisted-by: openai:gpt-5.5
1 parent bc90667 commit fc775f0

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

test/fixtures/process/different-registry-per-thread.mjs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ const registeredRefs = [];
55
const ref = { foo: 'foo' };
66
registeredRefs.push(ref);
77

8+
process.on('exit', () => {
9+
// Keep `ref` strongly reachable until exit so the per-thread finalization
10+
// callbacks are tested without depending on GC timing.
11+
registeredRefs.length;
12+
});
13+
814
if (isMainThread) {
915
process.finalization.register(ref, () => {
1016
process.stdout.write('shutdown on main thread\n');
@@ -13,7 +19,6 @@ if (isMainThread) {
1319
const worker = new Worker(import.meta.filename);
1420

1521
worker.on('error', (err) => {
16-
// Referencing `registeredRefs` here to avoid `ref` being GCed before the worker exits.
1722
console.log(registeredRefs);
1823
throw err;
1924
});

0 commit comments

Comments
 (0)