Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 64556ba

Browse filesBrowse 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
Copy full SHA for 64556ba

File tree

Expand file treeCollapse file tree

1 file changed

+17
-12
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+17
-12
lines changed
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-abortsignal-drop-settled-signals.mjs
+17-12Lines 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
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.