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