From 8288f57724ab4e6289dd2ba3ca0ada64a2513534 Mon Sep 17 00:00:00 2001 From: "Edigleysson Silva (Edy)" Date: Thu, 12 Dec 2024 15:34:28 -0300 Subject: [PATCH] test: fix test-abortsignal-drop-settled-signals flakiness MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/56197 Reviewed-By: Ruben Bridgewater Reviewed-By: Michaƫl Zasso Reviewed-By: Luigi Pinca Reviewed-By: Jason Zhang Reviewed-By: James M Snell Reviewed-By: Chemi Atlow --- .../test-abortsignal-drop-settled-signals.mjs | 39 ++++++++----------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/test/parallel/test-abortsignal-drop-settled-signals.mjs b/test/parallel/test-abortsignal-drop-settled-signals.mjs index f829fb0a9173fa..2bff3a3e063057 100644 --- a/test/parallel/test-abortsignal-drop-settled-signals.mjs +++ b/test/parallel/test-abortsignal-drop-settled-signals.mjs @@ -1,6 +1,7 @@ // Flags: --expose_gc // import '../common/index.mjs'; +import { gcUntil } from '../common/gc.js'; import { describe, it } from 'node:test'; function makeSubsequentCalls(limit, done, holdReferences = false) { @@ -141,37 +142,29 @@ it('drops settled dependant signals when signal is composite', (t, done) => { ); setImmediate(() => { - global.gc(); + global.gc({ execution: 'async' }).then(() => { + t.assert.strictEqual(composedSignalRef.deref(), undefined); + t.assert.strictEqual(controllers[0].signal[kDependantSignals].size, 2); + t.assert.strictEqual(controllers[1].signal[kDependantSignals].size, 1); - t.assert.strictEqual(composedSignalRef.deref(), undefined); - t.assert.strictEqual(controllers[0].signal[kDependantSignals].size, 2); - t.assert.strictEqual(controllers[1].signal[kDependantSignals].size, 1); - - setImmediate(() => { - t.assert.strictEqual(controllers[0].signal[kDependantSignals].size, 0); - t.assert.strictEqual(controllers[1].signal[kDependantSignals].size, 0); + setImmediate(() => { + t.assert.strictEqual(controllers[0].signal[kDependantSignals].size, 0); + t.assert.strictEqual(controllers[1].signal[kDependantSignals].size, 0); - done(); + done(); + }); }); }); }); it('drops settled signals even when there are listeners', (t, done) => { - runWithOrphanListeners(limit, (signalRefs) => { - setImmediate(() => { - global.gc(); - setImmediate(() => { - global.gc(); // One more call needed to clean up the deeper composed signals - setImmediate(() => { - global.gc(); // One more call needed to clean up the deeper composed signals - - const unGCedSignals = [...signalRefs].filter((ref) => ref.deref()); - - t.assert.strictEqual(unGCedSignals.length, 0); + runWithOrphanListeners(limit, async (signalRefs) => { + await gcUntil('all signals are GCed', () => { + const unGCedSignals = [...signalRefs].filter((ref) => ref.deref()); - done(); - }); - }); + return unGCedSignals.length === 0; }); + + done(); }); });