Skip to content

Commit

Permalink
test: use existing gc utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
geeksilva97 committed Dec 9, 2024
1 parent 248c191 commit 04e5a4b
Showing 1 changed file with 6 additions and 22 deletions.
28 changes: 6 additions & 22 deletions test/parallel/test-abortsignal-drop-settled-signals.mjs
Original file line number Diff line number Diff line change
@@ -1,26 +1,9 @@
// Flags: --expose_gc
//
import '../common/index.mjs';
import { gcUntil } from '../common/gc.js';
import { describe, it } from 'node:test';

function repeatSetImmediateAndGC(times, callback) {
let count = 0;

function next() {
if (count < times) {
count++;
setImmediate(() => {
global.gc();
next();
});
} else if (callback) {
callback();
}
}

next();
}

function makeSubsequentCalls(limit, done, holdReferences = false) {
let dependantSymbol;
let signalRef;
Expand Down Expand Up @@ -175,12 +158,13 @@ it('drops settled dependant signals when signal is composite', (t, done) => {
});

it('drops settled signals even when there are listeners', (t, done) => {
runWithOrphanListeners(limit, (signalRefs) => {
repeatSetImmediateAndGC(3, () => {
runWithOrphanListeners(limit, async (signalRefs) => {
await gcUntil('all signals are GCed', () => {
const unGCedSignals = [...signalRefs].filter((ref) => ref.deref());

t.assert.strictEqual(unGCedSignals.length, 0);
done();
return unGCedSignals.length === 0;
});

done();
});
});

0 comments on commit 04e5a4b

Please sign in to comment.