-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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 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: #40813 Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
- Loading branch information
1 parent
bbdcd05
commit d8a2125
Showing
13 changed files
with
281 additions
and
5 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
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(); | ||
} |
11 changes: 11 additions & 0 deletions
11
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,11 @@ | ||
'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); |
21 changes: 21 additions & 0 deletions
21
test/parallel/test-process-getactiveresources-track-interval-lifetime.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,21 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
|
||
const assert = require('assert'); | ||
|
||
assert.strictEqual(process.getActiveResourcesInfo().filter( | ||
(type) => type === 'Timeout').length, 0); | ||
|
||
let count = 0; | ||
const interval = setInterval(common.mustCall(() => { | ||
assert.strictEqual(process.getActiveResourcesInfo().filter( | ||
(type) => type === 'Timeout').length, 1); | ||
++count; | ||
if (count === 3) { | ||
clearInterval(interval); | ||
} | ||
}, 3), 0); | ||
|
||
assert.strictEqual(process.getActiveResourcesInfo().filter( | ||
(type) => type === 'Timeout').length, 1); |
20 changes: 20 additions & 0 deletions
20
test/parallel/test-process-getactiveresources-track-multiple-timers.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,20 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
for (let i = 0; i < 10; ++i) { | ||
for (let j = 0; j < 10; ++j) { | ||
setTimeout(common.mustCall(), i); | ||
} | ||
} | ||
|
||
assert.strictEqual(process.getActiveResourcesInfo().filter( | ||
(type) => type === 'Timeout').length, 100); | ||
|
||
for (let i = 0; i < 10; ++i) { | ||
setImmediate(common.mustCall()); | ||
} | ||
|
||
assert.strictEqual(process.getActiveResourcesInfo().filter( | ||
(type) => type === 'Immediate').length, 10); |
Oops, something went wrong.