Skip to content

Commit

Permalink
test: fix test-abortsignal-drop-settled-signals flakiness
Browse files Browse the repository at this point in the history
  • Loading branch information
geeksilva97 committed Dec 11, 2024
1 parent 80c0055 commit f735620
Showing 1 changed file with 16 additions and 23 deletions.
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();
});
});

0 comments on commit f735620

Please sign in to comment.