diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index 239f5258620c04..5e964b0a5dc282 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -154,10 +154,6 @@ const rawMethods = internalBinding('process_methods'); process.dlopen = rawMethods.dlopen; process.uptime = rawMethods.uptime; - // TODO(joyeecheung): either remove them or make them public - process._getActiveRequests = rawMethods._getActiveRequests; - process._getActiveHandles = rawMethods._getActiveHandles; - process.getActiveResourcesInfo = function() { const timerCounts = internalTimers.getTimerCounts(); return ArrayPrototypeConcat( diff --git a/src/node_process_methods.cc b/src/node_process_methods.cc index bc5d41382f20f1..aeb395ba1691d4 100644 --- a/src/node_process_methods.cc +++ b/src/node_process_methods.cc @@ -243,21 +243,6 @@ static void Uptime(const FunctionCallbackInfo& args) { args.GetReturnValue().Set(result); } -static void GetActiveRequests(const FunctionCallbackInfo& args) { - Environment* env = Environment::GetCurrent(args); - - std::vector> request_v; - for (ReqWrapBase* req_wrap : *env->req_wrap_queue()) { - AsyncWrap* w = req_wrap->GetAsyncWrap(); - if (w->persistent().IsEmpty()) - continue; - request_v.emplace_back(w->GetOwner()); - } - - args.GetReturnValue().Set( - Array::New(env->isolate(), request_v.data(), request_v.size())); -} - static void GetActiveRequestsInfo(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); @@ -273,21 +258,6 @@ static void GetActiveRequestsInfo(const FunctionCallbackInfo& args) { Array::New(env->isolate(), requests_info.data(), requests_info.size())); } -// Non-static, friend of HandleWrap. Could have been a HandleWrap method but -// implemented here for consistency with GetActiveRequests(). -void GetActiveHandles(const FunctionCallbackInfo& args) { - Environment* env = Environment::GetCurrent(args); - - std::vector> handle_v; - for (auto w : *env->handle_wrap_queue()) { - if (!HandleWrap::HasRef(w)) - continue; - handle_v.emplace_back(w->GetOwner()); - } - args.GetReturnValue().Set( - Array::New(env->isolate(), handle_v.data(), handle_v.size())); -} - void GetActiveHandlesInfo(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); @@ -576,9 +546,7 @@ static void Initialize(Local target, env->SetMethod(target, "cpuUsage", CPUUsage); env->SetMethod(target, "resourceUsage", ResourceUsage); - env->SetMethod(target, "_getActiveRequests", GetActiveRequests); env->SetMethod(target, "_getActiveRequestsInfo", GetActiveRequestsInfo); - env->SetMethod(target, "_getActiveHandles", GetActiveHandles); env->SetMethod(target, "_getActiveHandlesInfo", GetActiveHandlesInfo); env->SetMethod(target, "_kill", Kill); @@ -605,9 +573,7 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) { registry->Register(CPUUsage); registry->Register(ResourceUsage); - registry->Register(GetActiveRequests); registry->Register(GetActiveRequestsInfo); - registry->Register(GetActiveHandles); registry->Register(GetActiveHandlesInfo); registry->Register(Kill); diff --git a/test/parallel/test-process-getactivehandles.js b/test/parallel/test-process-getactivehandles.js index 2db3da3c563e6e..2adeaa07f8efcf 100644 --- a/test/parallel/test-process-getactivehandles.js +++ b/test/parallel/test-process-getactivehandles.js @@ -30,18 +30,23 @@ function clientConnected(client) { function checkAll() { - const handles = process._getActiveHandles(); + const handles = process.getActiveResourcesInfo(); + const tcpSocketResources = handles + .filter((resource) => resource === 'TCPSocketWrap').length; + + assert.ok(tcpSocketResources === clients_counter + connections.length, + '17 socket resources created'); clients.forEach(function(item) { - assert.ok(handles.includes(item)); item.destroy(); }); connections.forEach(function(item) { - assert.ok(handles.includes(item)); item.end(); }); - assert.ok(handles.includes(server)); + const tcpServerResources = handles + .filter((resource) => resource === 'TCPServerWrap').length; + assert.ok(tcpServerResources === 1, '1 server resource exists'); server.close(); } diff --git a/test/parallel/test-process-getactiverequests.js b/test/parallel/test-process-getactiverequests.js index ed3c0c8fe861ec..59f9e2023c86a5 100644 --- a/test/parallel/test-process-getactiverequests.js +++ b/test/parallel/test-process-getactiverequests.js @@ -7,4 +7,4 @@ const fs = require('fs'); for (let i = 0; i < 12; i++) fs.open(__filename, 'r', common.mustCall()); -assert.strictEqual(process._getActiveRequests().length, 12); +assert.strictEqual(process.getActiveResourcesInfo().length, 12); diff --git a/test/pseudo-tty/ref_keeps_node_running.js b/test/pseudo-tty/ref_keeps_node_running.js index 52761c140eddac..3d23baee91c4f9 100644 --- a/test/pseudo-tty/ref_keeps_node_running.js +++ b/test/pseudo-tty/ref_keeps_node_running.js @@ -6,6 +6,7 @@ require('../common'); const { internalBinding } = require('internal/test/binding'); const { TTY, isTTY } = internalBinding('tty_wrap'); const strictEqual = require('assert').strictEqual; +const TTY_RESOURCE_NAME = 'TTYWrap'; strictEqual(isTTY(0), true, 'fd 0 is not a TTY'); @@ -13,18 +14,20 @@ const handle = new TTY(0); handle.readStart(); handle.onread = () => {}; -function isHandleActive(handle) { - return process._getActiveHandles().some((active) => active === handle); +function isTTYActive(count) { + return process.getActiveResourcesInfo() + .filter((active) => active === TTY_RESOURCE_NAME) + .length === count; } -strictEqual(isHandleActive(handle), true, 'TTY handle not initially active'); +strictEqual(isTTYActive(1), true, 'TTY handle not initially active'); handle.unref(); -strictEqual(isHandleActive(handle), false, 'TTY handle active after unref()'); +strictEqual(isTTYActive(1), false, 'TTY handle active after unref()'); handle.ref(); -strictEqual(isHandleActive(handle), true, 'TTY handle inactive after ref()'); +strictEqual(isTTYActive(1), true, 'TTY handle inactive after ref()'); handle.unref();