Files
node/test/parallel/test-http-perf_hooks.js
Yagiz Nizipli 25c0c8e18a http: runtime deprecate instantiating without new
Promote DEP0195 from documentation-only to a runtime deprecation.
Calling node:http constructors without `new` now emits DEP0195 via
deprecateInstantiation. This covers Agent, Server, OutgoingMessage,
IncomingMessage, ServerResponse, and ClientRequest.

Update in-tree tests that called Server/Agent without `new` to use
the keyword, and add a dedicated DEP0195 coverage test.

Refs: https://github.com/nodejs/node/pull/58518
Assisted-by: Grok
Signed-off-by: Yagiz Nizipli <yagiz@nizipli.com>
PR-URL: https://github.com/nodejs/node/pull/64853
Reviewed-By: Aviv Keller <me@aviv.sh>
Reviewed-By: Tim Perry <pimterry@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2026-08-01 21:42:59 +00:00

84 lines
2.3 KiB
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const http = require('http');
const { PerformanceObserver } = require('perf_hooks');
const entries = [];
const obs = new PerformanceObserver(common.mustCallAtLeast((items) => {
entries.push(...items.getEntries());
}));
obs.observe({ type: 'http' });
const expected = 'Post Body For Test';
const makeRequest = common.mustCall((options) => {
return new Promise((resolve, reject) => {
http.request(options, common.mustCall((res) => {
resolve();
})).on('error', reject).end(options.data);
});
}, 2);
const server = new http.Server(common.mustCall((req, res) => {
let result = '';
req.setEncoding('utf8');
req.on('data', function(chunk) {
result += chunk;
});
req.on('end', common.mustCall(function() {
assert.strictEqual(result, expected);
res.writeHead(200);
res.end('hello world\n');
}));
}, 2));
let port;
server.listen(0, common.mustCall(async () => {
port = server.address().port;
await Promise.all([
makeRequest({
port,
path: '/',
method: 'POST',
data: expected
}),
makeRequest({
port,
path: '/',
method: 'POST',
data: expected
}),
]);
server.close();
}));
process.on('exit', () => {
let numberOfHttpClients = 0;
let numberOfHttpRequests = 0;
for (const entry of entries) {
assert.strictEqual(entry.entryType, 'http');
assert.strictEqual(typeof entry.startTime, 'number');
assert.strictEqual(typeof entry.duration, 'number');
if (entry.name === 'HttpClient') {
numberOfHttpClients++;
// The reported URL must include the port when it is non-default.
// Refs: https://github.com/nodejs/node/issues/59625
assert.strictEqual(entry.detail.req.url, `http://localhost:${port}/`);
} else if (entry.name === 'HttpRequest') {
numberOfHttpRequests++;
assert.strictEqual(entry.detail.req.url, '/');
}
assert.strictEqual(entry.detail.req.method, 'POST');
assert.strictEqual(typeof entry.detail.req.headers, 'object');
assert.strictEqual(entry.detail.res.statusCode, 200);
assert.strictEqual(entry.detail.res.statusMessage, 'OK');
assert.strictEqual(typeof entry.detail.res.headers, 'object');
}
assert.strictEqual(numberOfHttpClients, 2);
assert.strictEqual(numberOfHttpRequests, 2);
});