mirror of
https://github.com/nodejs/node.git
synced 2025-08-16 06:08:50 +02:00
http: trace http client by perf_hooks
PR-URL: https://github.com/nodejs/node/pull/42345 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Ricky Zhou <0x19951125@gmail.com>
This commit is contained in:
parent
44131ad638
commit
3f3fa6d990
5 changed files with 66 additions and 9 deletions
|
@ -5,13 +5,9 @@ const assert = require('assert');
|
|||
const http = require('http');
|
||||
|
||||
const { PerformanceObserver } = require('perf_hooks');
|
||||
|
||||
const entries = [];
|
||||
const obs = new PerformanceObserver(common.mustCallAtLeast((items) => {
|
||||
items.getEntries().forEach((entry) => {
|
||||
assert.strictEqual(entry.entryType, 'http');
|
||||
assert.strictEqual(typeof entry.startTime, 'number');
|
||||
assert.strictEqual(typeof entry.duration, 'number');
|
||||
});
|
||||
entries.push(...items.getEntries());
|
||||
}));
|
||||
|
||||
obs.observe({ type: 'http' });
|
||||
|
@ -57,3 +53,20 @@ server.listen(0, common.mustCall(async () => {
|
|||
]);
|
||||
server.close();
|
||||
}));
|
||||
|
||||
process.on('exit', () => {
|
||||
let numberOfHttpClients = 0;
|
||||
let numberOfHttpRequests = 0;
|
||||
entries.forEach((entry) => {
|
||||
assert.strictEqual(entry.entryType, 'http');
|
||||
assert.strictEqual(typeof entry.startTime, 'number');
|
||||
assert.strictEqual(typeof entry.duration, 'number');
|
||||
if (entry.name === 'HttpClient') {
|
||||
numberOfHttpClients++;
|
||||
} else if (entry.name === 'HttpRequest') {
|
||||
numberOfHttpRequests++;
|
||||
}
|
||||
});
|
||||
assert.strictEqual(numberOfHttpClients, 2);
|
||||
assert.strictEqual(numberOfHttpRequests, 2);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue