nodejs/test/parallel/test-diagnostics-channel-net-client-socket-tls.js
Darshan Sen 9eb9c26b26
net: always publish to 'net.client.socket' diagnostics channel
Previously, the 'net.client.socket' diagnostics channel was only
published to when `net.connect()` was called. This change ensures the
message is also published for the following calls:

- net.createConnection()
- net.Socket#connect()
- tls.connect()

Signed-off-by: Darshan Sen <raisinten@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/58349
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: theanarkh <theratliter@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
2025-05-18 09:05:17 +00:00

33 lines
926 B
JavaScript

'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
// This test ensures that the 'net.client.socket' diagnostics channel publishes
// a message when tls.connect() is used to create a socket connection.
const assert = require('assert');
const dc = require('diagnostics_channel');
const fixtures = require('../common/fixtures');
const tls = require('tls');
const options = {
key: fixtures.readKey('agent1-key.pem'),
cert: fixtures.readKey('agent1-cert.pem'),
rejectUnauthorized: false,
};
dc.subscribe('net.client.socket', common.mustCall(({ socket }) => {
assert.strictEqual(socket instanceof tls.TLSSocket, true);
}));
const server = tls.createServer(options, common.mustCall((socket) => {
socket.destroy();
server.close();
}));
server.listen({ port: 0 }, common.mustCall(() => {
const { port } = server.address();
tls.connect(port, options);
}));