-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 objects containing the `type`, `asyncId` and the `triggerAsyncId` of the currently active `requests`, `handles` and `timers`. Signed-off-by: Darshan Sen <[email protected]>
- Loading branch information
Showing
9 changed files
with
278 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
test/parallel/test-process-getactiveresources-track-active-handles.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
const assert = require('assert'); | ||
const net = require('net'); | ||
const NUM = 8; | ||
const connections = []; | ||
const clients = []; | ||
let clients_counter = 0; | ||
|
||
const server = net.createServer(function listener(c) { | ||
connections.push(c); | ||
}).listen(0, makeConnection); | ||
|
||
|
||
function makeConnection() { | ||
if (clients_counter >= NUM) return; | ||
net.connect(server.address().port, function connected() { | ||
clientConnected(this); | ||
makeConnection(); | ||
}); | ||
} | ||
|
||
|
||
function clientConnected(client) { | ||
clients.push(client); | ||
if (++clients_counter >= NUM) | ||
checkAll(); | ||
} | ||
|
||
|
||
function checkAll() { | ||
assert.strictEqual(process.getActiveResourcesInfo().filter( | ||
({ type }) => type === 'TCPSocketWrap').length, | ||
clients.length + connections.length); | ||
|
||
clients.forEach((item) => item.destroy()); | ||
connections.forEach((item) => item.end()); | ||
|
||
assert.strictEqual(process.getActiveResourcesInfo().filter( | ||
({ type }) => type === 'TCPServerWrap').length, 1); | ||
|
||
server.close(); | ||
} |
10 changes: 10 additions & 0 deletions
10
test/parallel/test-process-getactiveresources-track-active-requests.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const fs = require('fs'); | ||
|
||
for (let i = 0; i < 12; i++) | ||
fs.open(__filename, 'r', common.mustCall()); | ||
|
||
assert.strictEqual(process.getActiveResourcesInfo().length, 12); |
Oops, something went wrong.