node/test/parallel/test-process-ref-unref.js
Antoine du Hamel 9230f22029
Some checks are pending
Coverage Linux (without intl) / coverage-linux-without-intl (push) Waiting to run
Coverage Linux / coverage-linux (push) Waiting to run
Coverage Windows / coverage-windows (push) Waiting to run
Test and upload documentation to artifacts / build-docs (push) Waiting to run
Linters / lint-addon-docs (push) Waiting to run
Linters / lint-cpp (push) Waiting to run
Linters / format-cpp (push) Waiting to run
Linters / lint-js-and-md (push) Waiting to run
Linters / lint-py (push) Waiting to run
Linters / lint-yaml (push) Waiting to run
Linters / lint-sh (push) Waiting to run
Linters / lint-codeowners (push) Waiting to run
Linters / lint-pr-url (push) Waiting to run
Linters / lint-readme (push) Waiting to run
Notify on Push / Notify on Force Push on `main` (push) Waiting to run
Notify on Push / Notify on Push on `main` that lacks metadata (push) Waiting to run
Scorecard supply-chain security / Scorecard analysis (push) Waiting to run
process: remove support for undocumented symbol
PR-URL: https://github.com/nodejs/node/pull/56552
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
2025-01-12 15:05:44 +00:00

61 lines
1.2 KiB
JavaScript

'use strict';
require('../common');
const {
describe,
it,
} = require('node:test');
const {
strictEqual,
} = require('node:assert');
class Foo {
refCalled = 0;
unrefCalled = 0;
ref() {
this.refCalled++;
}
unref() {
this.unrefCalled++;
}
}
class Foo2 {
refCalled = 0;
unrefCalled = 0;
[Symbol.for('nodejs.ref')]() {
this.refCalled++;
}
[Symbol.for('nodejs.unref')]() {
this.unrefCalled++;
}
}
describe('process.ref/unref work as expected', () => {
it('refs...', () => {
// Objects that implement the new Symbol-based API
// just work.
const foo1 = new Foo();
const foo2 = new Foo2();
process.ref(foo1);
process.unref(foo1);
process.ref(foo2);
process.unref(foo2);
strictEqual(foo1.refCalled, 1);
strictEqual(foo1.unrefCalled, 1);
strictEqual(foo2.refCalled, 1);
strictEqual(foo2.unrefCalled, 1);
// Objects that implement the legacy API also just work.
const i = setInterval(() => {}, 1000);
strictEqual(i.hasRef(), true);
process.unref(i);
strictEqual(i.hasRef(), false);
process.ref(i);
strictEqual(i.hasRef(), true);
clearInterval(i);
});
});