Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix test-abortsignal-drop-settled-signals flakiness #56197

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 16 additions & 23 deletions test/parallel/test-abortsignal-drop-settled-signals.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Flags: --expose_gc
//
import '../common/index.mjs';
import { gcUntil } from '../common/gc.js';
import { describe, it } from 'node:test';

function makeSubsequentCalls(limit, done, holdReferences = false) {
Expand Down Expand Up @@ -141,37 +142,29 @@ it('drops settled dependant signals when signal is composite', (t, done) => {
);

setImmediate(() => {
global.gc();
global.gc({ execution: 'async' }).then(() => {
t.assert.strictEqual(composedSignalRef.deref(), undefined);
t.assert.strictEqual(controllers[0].signal[kDependantSignals].size, 2);
t.assert.strictEqual(controllers[1].signal[kDependantSignals].size, 1);

t.assert.strictEqual(composedSignalRef.deref(), undefined);
t.assert.strictEqual(controllers[0].signal[kDependantSignals].size, 2);
t.assert.strictEqual(controllers[1].signal[kDependantSignals].size, 1);

setImmediate(() => {
t.assert.strictEqual(controllers[0].signal[kDependantSignals].size, 0);
t.assert.strictEqual(controllers[1].signal[kDependantSignals].size, 0);
setImmediate(() => {
t.assert.strictEqual(controllers[0].signal[kDependantSignals].size, 0);
t.assert.strictEqual(controllers[1].signal[kDependantSignals].size, 0);

done();
done();
});
});
});
});

it('drops settled signals even when there are listeners', (t, done) => {
runWithOrphanListeners(limit, (signalRefs) => {
setImmediate(() => {
global.gc();
setImmediate(() => {
global.gc(); // One more call needed to clean up the deeper composed signals
setImmediate(() => {
global.gc(); // One more call needed to clean up the deeper composed signals

const unGCedSignals = [...signalRefs].filter((ref) => ref.deref());

t.assert.strictEqual(unGCedSignals.length, 0);
runWithOrphanListeners(limit, async (signalRefs) => {
await gcUntil('all signals are GCed', () => {
const unGCedSignals = [...signalRefs].filter((ref) => ref.deref());

done();
});
});
return unGCedSignals.length === 0;
});

done();
});
});
Loading