node/test/parallel/test-abortcontroller-internal.js
James M Snell 39215e1cfa test: refactor test-abortcontroller to use node:test
Starting the long process of refactoring our own tests to use
the node:test module and mocks.

PR-URL: https://github.com/nodejs/node/pull/54574
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2024-08-28 18:50:53 -07:00

35 lines
823 B
JavaScript

// Flags: --no-warnings --expose-gc --expose-internals
'use strict';
require('../common');
const {
strictEqual,
} = require('assert');
const {
test,
} = require('node:test');
const {
kWeakHandler,
} = require('internal/event_target');
const { setTimeout: sleep } = require('timers/promises');
// The tests in this file depend on Node.js internal APIs. These are not necessarily
// portable to other runtimes
test('A weak event listener should not prevent gc', async () => {
// If the event listener is weak, however, it should not prevent gc
let ref;
function handler() {}
{
ref = new globalThis.WeakRef(AbortSignal.timeout(1_200_000));
ref.deref().addEventListener('abort', handler, { [kWeakHandler]: {} });
}
await sleep(10);
globalThis.gc();
strictEqual(ref.deref(), undefined);
});