Skip to content

Commit

Permalink
test: improve abort signal dropping test
Browse files Browse the repository at this point in the history
  • Loading branch information
geeksilva97 committed Dec 22, 2024
1 parent 31c20f6 commit 50a5763
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions test/parallel/test-abortsignal-drop-settled-signals.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});
Expand Down

0 comments on commit 50a5763

Please sign in to comment.