test: improve abort signal dropping test
Some checks are pending
Coverage Linux (without intl) / coverage-linux-without-intl (push) Waiting to run
Coverage Linux / coverage-linux (push) Waiting to run
Coverage Windows / coverage-windows (push) Waiting to run
Test and upload documentation to artifacts / build-docs (push) Waiting to run
Linters / lint-addon-docs (push) Waiting to run
Linters / lint-cpp (push) Waiting to run
Linters / format-cpp (push) Waiting to run
Linters / lint-js-and-md (push) Waiting to run
Linters / lint-py (push) Waiting to run
Linters / lint-yaml (push) Waiting to run
Linters / lint-sh (push) Waiting to run
Linters / lint-codeowners (push) Waiting to run
Linters / lint-pr-url (push) Waiting to run
Linters / lint-readme (push) Waiting to run
Notify on Push / Notify on Force Push on `main` (push) Waiting to run
Notify on Push / Notify on Push on `main` that lacks metadata (push) Waiting to run
Scorecard supply-chain security / Scorecard analysis (push) Waiting to run

PR-URL: https://github.com/nodejs/node/pull/56339
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Jason Zhang <xzha4350@gmail.com>
This commit is contained in:
Edy Silva 2024-12-26 11:57:17 -03:00 committed by GitHub
parent c0edd30414
commit c94a9dbc40
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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)'
);
t.assert.strictEqual(controllers[0].signal[kDependantSignals].size, 2);
t.assert.strictEqual(controllers[1].signal[kDependantSignals].size, 1);
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);
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
);
setImmediate(() => {
t.assert.strictEqual(controllers[0].signal[kDependantSignals].size, 0);
t.assert.strictEqual(controllers[1].signal[kDependantSignals].size, 0);
done();
return composedSignalRef.deref() === undefined && totalDependantSignals === 0;
});
done();
});
});
});