Skip to content

Commit d3cc655

Browse files
committed
test: test settled signals when AbortSignal.any receives a composite signal
1 parent 5f0939f commit d3cc655

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

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

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const makeSubsequentCalls = (limit, done, holdReferences = false) => {
1313
let signalRef;
1414
const ac = new AbortController();
1515
const retainedSignals = [];
16-
const handler = () => {};
16+
const handler = () => { };
1717

1818
function run(iteration) {
1919
if (iteration > limit) {
@@ -106,28 +106,27 @@ describe('when there is a short-lived signal', () => {
106106
});
107107
});
108108

109-
// describe('when provided signal is composed', () => {
110-
// it('drops settled dependant signals', (t, done) => {
111-
// const controllers = Array.from({ length: 2 }, () => new AbortController());
112-
// const composedSignal1 = AbortSignal.any([controllers[0].signal]);
113-
// const composedSignalRef = new WeakRef(AbortSignal.any([composedSignal1, controllers[1].signal]));
109+
it('drops settled dependant signals when signal is composite', (t, done) => {
110+
const controllers = Array.from({ length: 2 }, () => new AbortController());
111+
const composedSignal1 = AbortSignal.any([controllers[0].signal]);
112+
const composedSignalRef = new WeakRef(AbortSignal.any([composedSignal1, controllers[1].signal]));
114113

115-
// global.gc();
114+
const kDependantSignals = Object.getOwnPropertySymbols(controllers[0].signal).find(
115+
(s) => s.toString() === 'Symbol(kDependantSignals)'
116+
);
116117

117-
// setImmediate(() => {
118-
// // Object.getOwnPropertySymbols(composedSignal1).forEach((s) => {
119-
// // console.log(s, composedSignal1[s]);
120-
// // });
118+
setImmediate(() => {
119+
global.gc();
121120

122-
// // console.log('signal 2 ====')
121+
t.assert.equal(composedSignalRef.deref(), undefined);
122+
t.assert.equal(controllers[0].signal[kDependantSignals].size, 2);
123+
t.assert.equal(controllers[1].signal[kDependantSignals].size, 1);
123124

124-
// const composedSignal2 = composedSignalRef.deref();
125-
126-
// Object.getOwnPropertySymbols(composedSignal2).forEach((s) => {
127-
// console.log(s, composedSignal2[s]);
128-
// });
129-
// done();
130-
// });
125+
setImmediate(() => {
126+
t.assert.equal(controllers[0].signal[kDependantSignals].size, 0);
127+
t.assert.equal(controllers[1].signal[kDependantSignals].size, 0);
131128

132-
// });
133-
// });
129+
done();
130+
});
131+
});
132+
});

0 commit comments

Comments
 (0)