mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
39215e1cfa
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>
35 lines
823 B
JavaScript
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);
|
|
});
|