From 04e5a4b6cbd275ccca58d89ae2fbfa57a1b982eb Mon Sep 17 00:00:00 2001 From: Edy Silva Date: Mon, 9 Dec 2024 15:00:48 -0300 Subject: [PATCH] test: use existing gc utilities --- .../test-abortsignal-drop-settled-signals.mjs | 28 ++++--------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/test/parallel/test-abortsignal-drop-settled-signals.mjs b/test/parallel/test-abortsignal-drop-settled-signals.mjs index 2be19b1809836b..2bff3a3e063057 100644 --- a/test/parallel/test-abortsignal-drop-settled-signals.mjs +++ b/test/parallel/test-abortsignal-drop-settled-signals.mjs @@ -1,26 +1,9 @@ // Flags: --expose_gc // import '../common/index.mjs'; +import { gcUntil } from '../common/gc.js'; import { describe, it } from 'node:test'; -function repeatSetImmediateAndGC(times, callback) { - let count = 0; - - function next() { - if (count < times) { - count++; - setImmediate(() => { - global.gc(); - next(); - }); - } else if (callback) { - callback(); - } - } - - next(); -} - function makeSubsequentCalls(limit, done, holdReferences = false) { let dependantSymbol; let signalRef; @@ -175,12 +158,13 @@ it('drops settled dependant signals when signal is composite', (t, done) => { }); it('drops settled signals even when there are listeners', (t, done) => { - runWithOrphanListeners(limit, (signalRefs) => { - repeatSetImmediateAndGC(3, () => { + runWithOrphanListeners(limit, async (signalRefs) => { + await gcUntil('all signals are GCed', () => { const unGCedSignals = [...signalRefs].filter((ref) => ref.deref()); - t.assert.strictEqual(unGCedSignals.length, 0); - done(); + return unGCedSignals.length === 0; }); + + done(); }); });