From 50a57631e46193d8f66635cdeb9683c345ef1ed8 Mon Sep 17 00:00:00 2001 From: Edy Silva Date: Sun, 22 Dec 2024 13:26:26 -0300 Subject: [PATCH] test: improve abort signal dropping test --- .../test-abortsignal-drop-settled-signals.mjs | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/test/parallel/test-abortsignal-drop-settled-signals.mjs b/test/parallel/test-abortsignal-drop-settled-signals.mjs index 2bff3a3e063057..0abcaf81012716 100644 --- a/test/parallel/test-abortsignal-drop-settled-signals.mjs +++ b/test/parallel/test-abortsignal-drop-settled-signals.mjs @@ -134,25 +134,30 @@ it('does not prevent source signal from being GCed if it is short-lived', (t, do it('drops settled dependant signals when signal is composite', (t, done) => { const controllers = Array.from({ length: 2 }, () => new AbortController()); - const composedSignal1 = AbortSignal.any([controllers[0].signal]); - const composedSignalRef = new WeakRef(AbortSignal.any([composedSignal1, controllers[1].signal])); + + // Using WeakRefs to avoid this test to retain information that will make the test fail + const composedSignal1 = new WeakRef(AbortSignal.any([controllers[0].signal])); + const composedSignalRef = new WeakRef(AbortSignal.any([composedSignal1.deref(), controllers[1].signal])); const kDependantSignals = Object.getOwnPropertySymbols(controllers[0].signal).find( (s) => s.toString() === 'Symbol(kDependantSignals)' ); - setImmediate(() => { - 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); - - setImmediate(() => { - t.assert.strictEqual(controllers[0].signal[kDependantSignals].size, 0); - t.assert.strictEqual(controllers[1].signal[kDependantSignals].size, 0); + t.assert.strictEqual(controllers[0].signal[kDependantSignals].size, 2); + t.assert.strictEqual(controllers[1].signal[kDependantSignals].size, 1); - done(); + setImmediate(() => { + global.gc({ execution: 'async' }).then(async () => { + await gcUntil('all signals are GCed', () => { + const totalDependantSignals = Math.max( + controllers[0].signal[kDependantSignals].size, + controllers[1].signal[kDependantSignals].size + ); + + return composedSignalRef.deref() === undefined && totalDependantSignals === 0; }); + + done(); }); }); });