0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-process-getactiveresources-track-timer-lifetime.js
Darshan Sen 0d9f3bd9e8
process: add getActiveResourcesInfo()
This is supposed to be a public alternative of the private APIs,
`process._getActiveResources()` and `process._getActiveHandles()`. When
called, it returns an array of strings containing the types of the
active resources that are currently keeping the event loop alive.

Signed-off-by: Darshan Sen <darshan.sen@postman.com>

PR-URL: https://github.com/nodejs/node/pull/40813
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2021-12-14 14:09:08 +00:00

42 lines
1.4 KiB
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
{
assert.strictEqual(process.getActiveResourcesInfo().filter(
(type) => type === 'Timeout').length, 0);
const timeout = setTimeout(common.mustCall(() => {
assert.strictEqual(process.getActiveResourcesInfo().filter(
(type) => type === 'Timeout').length, 1);
clearTimeout(timeout);
assert.strictEqual(process.getActiveResourcesInfo().filter(
(type) => type === 'Timeout').length, 0);
}), 0);
assert.strictEqual(process.getActiveResourcesInfo().filter(
(type) => type === 'Timeout').length, 1);
}
{
assert.strictEqual(process.getActiveResourcesInfo().filter(
(type) => type === 'Immediate').length, 0);
const immediate = setImmediate(common.mustCall(() => {
// TODO(RaisinTen): Change this test to the following when the Immediate is
// destroyed and unrefed after the callback gets executed.
// assert.strictEqual(process.getActiveResourcesInfo().filter(
// (type) => type === 'Immediate').length, 1);
assert.strictEqual(process.getActiveResourcesInfo().filter(
(type) => type === 'Immediate').length, 0);
clearImmediate(immediate);
assert.strictEqual(process.getActiveResourcesInfo().filter(
(type) => type === 'Immediate').length, 0);
}));
assert.strictEqual(process.getActiveResourcesInfo().filter(
(type) => type === 'Immediate').length, 1);
}