mirror of
https://github.com/nodejs/node.git
synced 2026-10-28 10:15:07 +08:00
Reviewing the performance of http tests in the smartos CI runs revealed that a handful of HTTP related tests are running way longer than they should, with some hitting upwards of 66 seconds! - Ten HTTP/HTTPS tests now close connections deterministically instead of waiting 66 seconds. - Two HTTP/2 tests use an explicit 64KiB stream window and 3MB payload, while restoring timeout assertions. - Estimated SmartOS CI saving: about 4.5 minutes at -j4. Signed-off-by: James M Snell <jasnell@gmail.com> Assisted-by: Opencode PR-URL: https://github.com/nodejs/node/pull/65926 Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Tim Perry <pimterry@gmail.com>
60 lines
1.6 KiB
JavaScript
60 lines
1.6 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
|
|
if (!common.hasCrypto)
|
|
common.skip('missing crypto');
|
|
|
|
const https = require('https');
|
|
const http = require('http');
|
|
const net = require('net');
|
|
const assert = require('assert');
|
|
const tls = require('tls');
|
|
const fixtures = require('../common/fixtures');
|
|
|
|
function request(socket) {
|
|
socket.write('GET / HTTP/1.1\r\nHost: localhost\r\nConnection: keep-alive\r\n\r\n\r\n');
|
|
}
|
|
|
|
// https options
|
|
const httpsOptions = {
|
|
key: fixtures.readKey('agent1-key.pem'),
|
|
cert: fixtures.readKey('agent1-cert.pem')
|
|
};
|
|
|
|
const server = https.createServer(httpsOptions, common.mustCall((req, res) => {
|
|
res.end('ok');
|
|
}));
|
|
|
|
server.on('dropRequest', common.mustCall((request, socket) => {
|
|
assert.strictEqual(request instanceof http.IncomingMessage, true);
|
|
assert.strictEqual(socket instanceof net.Socket, true);
|
|
server.close();
|
|
}));
|
|
|
|
server.listen(0, common.mustCall(() => {
|
|
const socket = tls.connect(
|
|
server.address().port,
|
|
{
|
|
rejectUnauthorized: false
|
|
},
|
|
common.mustCall(() => {
|
|
let response = '';
|
|
request(socket);
|
|
request(socket);
|
|
socket.on('error', common.mustNotCall());
|
|
socket.on('data', common.mustCallAtLeast((chunk) => {
|
|
response += chunk;
|
|
if (response.includes('HTTP/1.1 503 Service Unavailable'))
|
|
socket.end();
|
|
}));
|
|
socket.on('close', common.mustCall(() => {
|
|
assert.match(response, /HTTP\/1\.1 200 OK/);
|
|
assert.match(response, /HTTP\/1\.1 503 Service Unavailable/);
|
|
}));
|
|
})
|
|
);
|
|
}));
|
|
|
|
server.maxRequestsPerSocket = 1;
|