1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
'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);
entries.forEach((entry) => {
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);
});
});
|