Skip to content

Commit b6c3869

Browse files
geeksilva97aduh95
authored andcommittedJan 31, 2025
test: improve abort signal dropping test
PR-URL: #56339 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Jason Zhang <xzha4350@gmail.com>
1 parent cc648ef commit b6c3869

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed
 

‎test/parallel/test-abortsignal-drop-settled-signals.mjs

+17-12
Original file line numberDiff line numberDiff line change
@@ -134,25 +134,30 @@ it('does not prevent source signal from being GCed if it is short-lived', (t, do
134134

135135
it('drops settled dependant signals when signal is composite', (t, done) => {
136136
const controllers = Array.from({ length: 2 }, () => new AbortController());
137-
const composedSignal1 = AbortSignal.any([controllers[0].signal]);
138-
const composedSignalRef = new WeakRef(AbortSignal.any([composedSignal1, controllers[1].signal]));
137+
138+
// Using WeakRefs to avoid this test to retain information that will make the test fail
139+
const composedSignal1 = new WeakRef(AbortSignal.any([controllers[0].signal]));
140+
const composedSignalRef = new WeakRef(AbortSignal.any([composedSignal1.deref(), controllers[1].signal]));
139141

140142
const kDependantSignals = Object.getOwnPropertySymbols(controllers[0].signal).find(
141143
(s) => s.toString() === 'Symbol(kDependantSignals)'
142144
);
143145

144-
setImmediate(() => {
145-
global.gc({ execution: 'async' }).then(() => {
146-
t.assert.strictEqual(composedSignalRef.deref(), undefined);
147-
t.assert.strictEqual(controllers[0].signal[kDependantSignals].size, 2);
148-
t.assert.strictEqual(controllers[1].signal[kDependantSignals].size, 1);
149-
150-
setImmediate(() => {
151-
t.assert.strictEqual(controllers[0].signal[kDependantSignals].size, 0);
152-
t.assert.strictEqual(controllers[1].signal[kDependantSignals].size, 0);
146+
t.assert.strictEqual(controllers[0].signal[kDependantSignals].size, 2);
147+
t.assert.strictEqual(controllers[1].signal[kDependantSignals].size, 1);
153148

154-
done();
149+
setImmediate(() => {
150+
global.gc({ execution: 'async' }).then(async () => {
151+
await gcUntil('all signals are GCed', () => {
152+
const totalDependantSignals = Math.max(
153+
controllers[0].signal[kDependantSignals].size,
154+
controllers[1].signal[kDependantSignals].size
155+
);
156+
157+
return composedSignalRef.deref() === undefined && totalDependantSignals === 0;
155158
});
159+
160+
done();
156161
});
157162
});
158163
});

0 commit comments

Comments
 (0)
Please sign in to comment.