Skip to content

Commit 64556ba

Browse files
geeksilva97aduh95
authored andcommitted
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 accbdad commit 64556ba

1 file changed

Lines changed: 17 additions & 12 deletions

File tree

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

Lines changed: 17 additions & 12 deletions
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
constcontrollers=Array.from({length: 2},()=>newAbortController());
137-
constcomposedSignal1=AbortSignal.any([controllers[0].signal]);
138-
constcomposedSignalRef=newWeakRef(AbortSignal.any([composedSignal1,controllers[1].signal]));
137+
138+
// Using WeakRefs to avoid this test to retain information that will make the test fail
139+
constcomposedSignal1=newWeakRef(AbortSignal.any([controllers[0].signal]));
140+
constcomposedSignalRef=newWeakRef(AbortSignal.any([composedSignal1.deref(),controllers[1].signal]));
139141

140142
constkDependantSignals=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+
awaitgcUntil('all signals are GCed',()=>{
152+
consttotalDependantSignals=Math.max(
153+
controllers[0].signal[kDependantSignals].size,
154+
controllers[1].signal[kDependantSignals].size
155+
);
156+
157+
returncomposedSignalRef.deref()===undefined&&totalDependantSignals===0;
155158
});
159+
160+
done();
156161
});
157162
});
158163
});

0 commit comments

Comments
 (0)