Skip to content

Commit 1550729

Browse files
committed
test: ensure short-lived signals are GCed
1 parent 08f548d commit 1550729

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,26 @@ const makeSubsequentCalls = (limit, done, holdReferences = false) => {
3939
run(1);
4040
};
4141

42+
const runShortLivedSourceSignal = (limit, done) => {
43+
const signalRefs = new Set();
44+
45+
function run(iteration) {
46+
if (iteration > limit) {
47+
global.gc();
48+
done(signalRefs);
49+
return;
50+
}
51+
52+
const ac = new AbortController();
53+
signalRefs.add(new WeakRef(ac.signal));
54+
AbortSignal.any([ac.signal]);
55+
56+
setImmediate(() => run(iteration + 1));
57+
}
58+
59+
run(1);
60+
};
61+
4262
const limit = 10_000;
4363

4464
describe('when there is a long-lived signal', () => {
@@ -59,3 +79,16 @@ describe('when there is a long-lived signal', () => {
5979
}, true);
6080
});
6181
});
82+
83+
describe('when there is a short-lived signal', () => {
84+
it('does not prevent source signal from being GCed', (t, done) => {
85+
runShortLivedSourceSignal(limit, (signalRefs) => {
86+
setImmediate(() => {
87+
const unGCedSignals = [...signalRefs].filter((ref) => ref.deref());
88+
89+
t.assert.equal(unGCedSignals, 0);
90+
done();
91+
});
92+
});
93+
});
94+
});

0 commit comments

Comments
 (0)