2016-02-19 17:03:16 -08:00
|
|
|
'use strict';
|
2019-05-29 11:43:44 -07:00
|
|
|
const fixtures = require('../../test/common/fixtures');
|
2018-02-17 03:51:11 +01:00
|
|
|
const tls = require('tls');
|
2013-02-11 14:38:00 -08:00
|
|
|
|
2017-09-13 22:48:53 -03:00
|
|
|
const common = require('../common.js');
|
|
|
|
const bench = common.createBenchmark(main, {
|
2013-02-11 14:38:00 -08:00
|
|
|
concurrency: [1, 10],
|
2023-01-29 20:13:35 +02:00
|
|
|
dur: [5],
|
2013-02-11 14:38:00 -08:00
|
|
|
});
|
|
|
|
|
2020-02-14 14:17:20 +01:00
|
|
|
let clientConn = 0;
|
|
|
|
let serverConn = 0;
|
|
|
|
let dur;
|
|
|
|
let concurrency;
|
|
|
|
let running = true;
|
2013-02-11 14:38:00 -08:00
|
|
|
|
2018-01-23 13:15:59 +01:00
|
|
|
function main(conf) {
|
|
|
|
dur = conf.dur;
|
|
|
|
concurrency = conf.concurrency;
|
2017-09-13 22:48:53 -03:00
|
|
|
const options = {
|
2019-05-29 11:43:44 -07:00
|
|
|
key: fixtures.readKey('rsa_private.pem'),
|
|
|
|
cert: fixtures.readKey('rsa_cert.crt'),
|
|
|
|
ca: fixtures.readKey('rsa_ca.crt'),
|
2022-06-27 10:47:13 +02:00
|
|
|
ciphers: 'AES256-GCM-SHA384',
|
|
|
|
maxVersion: 'TLSv1.2',
|
2016-11-24 11:43:35 -08:00
|
|
|
};
|
2013-02-11 14:38:00 -08:00
|
|
|
|
2018-01-23 13:15:59 +01:00
|
|
|
const server = tls.createServer(options, onConnection);
|
2013-02-11 14:38:00 -08:00
|
|
|
server.listen(common.PORT, onListening);
|
|
|
|
}
|
|
|
|
|
|
|
|
function onListening() {
|
|
|
|
setTimeout(done, dur * 1000);
|
|
|
|
bench.start();
|
2019-07-31 08:26:38 -05:00
|
|
|
for (let i = 0; i < concurrency; i++)
|
2013-02-11 14:38:00 -08:00
|
|
|
makeConnection();
|
|
|
|
}
|
|
|
|
|
|
|
|
function onConnection(conn) {
|
|
|
|
serverConn++;
|
|
|
|
}
|
|
|
|
|
|
|
|
function makeConnection() {
|
2017-09-13 22:48:53 -03:00
|
|
|
const options = {
|
2016-11-24 11:43:35 -08:00
|
|
|
port: common.PORT,
|
2023-01-29 20:13:35 +02:00
|
|
|
rejectUnauthorized: false,
|
2016-11-24 11:43:35 -08:00
|
|
|
};
|
2019-03-26 05:21:27 +01:00
|
|
|
const conn = tls.connect(options, () => {
|
2013-02-11 14:38:00 -08:00
|
|
|
clientConn++;
|
2019-02-04 22:06:08 -08:00
|
|
|
conn.on('error', (er) => {
|
2013-02-11 14:38:00 -08:00
|
|
|
console.error('client error', er);
|
|
|
|
throw er;
|
|
|
|
});
|
|
|
|
conn.end();
|
|
|
|
if (running) makeConnection();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function done() {
|
|
|
|
running = false;
|
2018-12-10 13:27:32 +01:00
|
|
|
// It's only an established connection if they both saw it.
|
2013-02-11 14:38:00 -08:00
|
|
|
// because we destroy the server somewhat abruptly, these
|
|
|
|
// don't always match. Generally, serverConn will be
|
|
|
|
// the smaller number, but take the min just to be sure.
|
|
|
|
bench.end(Math.min(serverConn, clientConn));
|
2016-05-31 21:49:16 +02:00
|
|
|
process.exit(0);
|
2013-02-11 14:38:00 -08:00
|
|
|
}
|