0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-net-perf_hooks.js
Narcisa Codreanu 2fe511ba23
test: replace forEach() in test-net-perf_hooks with for of
PR-URL: https://github.com/nodejs/node/pull/49831
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Joe Sepi <sepi@joesepi.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
2023-10-06 14:25:15 +00:00

61 lines
1.5 KiB
JavaScript

'use strict';
const common = require('../common');
const tmpdir = require('../common/tmpdir');
const assert = require('assert');
const net = require('net');
tmpdir.refresh();
const { PerformanceObserver } = require('perf_hooks');
const entries = [];
const obs = new PerformanceObserver(common.mustCallAtLeast((items) => {
entries.push(...items.getEntries());
}));
obs.observe({ type: 'net' });
{
const server = net.createServer(common.mustCall((socket) => {
socket.destroy();
}));
server.listen(0, common.mustCall(async () => {
await new Promise((resolve, reject) => {
const socket = net.connect(server.address().port);
socket.on('end', resolve);
socket.on('error', reject);
});
server.close();
}));
}
{
const server = net.createServer(common.mustCall((socket) => {
socket.destroy();
}));
server.listen(common.PIPE, common.mustCall(async () => {
await new Promise((resolve, reject) => {
const socket = net.connect(common.PIPE);
socket.on('end', resolve);
socket.on('error', reject);
});
server.close();
}));
}
process.on('exit', () => {
assert.strictEqual(entries.length, 1);
for (const entry of entries) {
assert.strictEqual(entry.name, 'connect');
assert.strictEqual(entry.entryType, 'net');
assert.strictEqual(typeof entry.startTime, 'number');
assert.strictEqual(typeof entry.duration, 'number');
assert.strictEqual(!!entry.detail.host, true);
assert.strictEqual(!!entry.detail.port, true);
}
});