mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
test: implement low-risk test optimizations
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>
This commit is contained in:
1 parent
241339f072
commit
047d7c53d2
12 files changed
+43
-18
No files matched your search
@@ -14,7 +14,7 @@ const server = http.createServer(function(req, res) {
|
||||
res.writeHead(200, { 'Content-Type': 'text/plain' });
|
||||
res.end('bye');
|
||||
}).listen(0, function() {
|
||||
http.get({ port: this.address().port }, function(res) {
|
||||
http.get({ port: this.address().port, agent: false }, function(res) {
|
||||
res.resume();
|
||||
throw new Error('get did fail');
|
||||
}).on('close', function() {
|
||||
|
||||
@@ -16,5 +16,6 @@ server.listen(0, '127.0.0.1', common.mustCall(function() {
|
||||
port: this.address().port,
|
||||
});
|
||||
req.setHeader('foo', 'bar');
|
||||
req.setHeader('Connection', 'close');
|
||||
req.flushHeaders();
|
||||
}));
|
||||
@@ -11,6 +11,11 @@ const server = http.createServer(common.mustCallAtLeast((req, res) => {
|
||||
req.pipe(res);
|
||||
}));
|
||||
|
||||
// The malformed request intentionally has no valid Connection header.
|
||||
// So we have to set an explicitly shorter-than-default timeout.
|
||||
server.keepAliveTimeout = common.platformTimeout(100);
|
||||
server.keepAliveTimeoutBuffer = 0;
|
||||
|
||||
server.listen(0, common.mustCall(function() {
|
||||
const bufs = [];
|
||||
const client = net.connect(
|
||||
|
||||
@@ -24,12 +24,20 @@ server.on('dropRequest', common.mustCall((request, socket) => {
|
||||
|
||||
server.listen(0, common.mustCall(() => {
|
||||
const socket = net.connect(server.address().port);
|
||||
let response = '';
|
||||
socket.on('connect', common.mustCall(() => {
|
||||
request(socket);
|
||||
request(socket);
|
||||
}));
|
||||
socket.on('data', common.mustCallAtLeast());
|
||||
socket.on('close', common.mustCall());
|
||||
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;
|
||||
@@ -27,7 +27,8 @@ const server = http
|
||||
.listen(0, function() {
|
||||
const s = net.connect(this.address().port);
|
||||
|
||||
const big = 'GET / HTTP/1.1\r\nHost: example.com\r\n\r\n'.repeat(COUNT);
|
||||
const big = 'GET / HTTP/1.1\r\nHost: example.com\r\n\r\n'.repeat(COUNT - 1) +
|
||||
'GET / HTTP/1.1\r\nHost: example.com\r\nConnection: close\r\n\r\n';
|
||||
|
||||
s.write(big);
|
||||
s.resume();
|
||||
|
||||
@@ -40,7 +40,7 @@ const assert = require('assert');
|
||||
}));
|
||||
|
||||
server.listen(0, common.mustCall(() => {
|
||||
http.get({ port: server.address().port }, common.mustCall());
|
||||
http.get({ port: server.address().port, agent: false }, common.mustCall());
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ const assert = require('assert');
|
||||
}));
|
||||
|
||||
server.listen(0, common.mustCall(() => {
|
||||
http.get({ port: server.address().port }, common.mustCall());
|
||||
http.get({ port: server.address().port, agent: false }, common.mustCall());
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -126,6 +126,6 @@ const assert = require('assert');
|
||||
}));
|
||||
|
||||
server.listen(0, common.mustCall(() => {
|
||||
http.get({ port: server.address().port }, common.mustCall());
|
||||
http.get({ port: server.address().port, agent: false }, common.mustCall());
|
||||
}));
|
||||
}
|
||||
@@ -192,7 +192,6 @@ test(function fastTimeout(cb) {
|
||||
|
||||
const server = http.createServer(common.mustCall((req, res) => {
|
||||
req.on('timeout', common.mustNotCall());
|
||||
res.end();
|
||||
connectionHandlerInvoked = true;
|
||||
invokeCallbackIfDone();
|
||||
}));
|
||||
|
||||
@@ -39,11 +39,19 @@ server.listen(0, common.mustCall(() => {
|
||||
rejectUnauthorized: false
|
||||
},
|
||||
common.mustCall(() => {
|
||||
let response = '';
|
||||
request(socket);
|
||||
request(socket);
|
||||
socket.on('error', common.mustNotCall());
|
||||
socket.on('data', common.mustCallAtLeast());
|
||||
socket.on('close', common.mustCall());
|
||||
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/);
|
||||
}));
|
||||
})
|
||||
);
|
||||
}));
|
||||
|
||||
@@ -216,7 +216,6 @@ test(function fastTimeout(cb) {
|
||||
const server = https.createServer(serverOptions, common.mustCall(
|
||||
(req, res) => {
|
||||
req.on('timeout', common.mustNotCall());
|
||||
res.end();
|
||||
connectionHandlerInvoked = true;
|
||||
invokeCallbackIfDone();
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ const minReadSize = 500000;
|
||||
const serverTimeout = common.platformTimeout(500);
|
||||
let offsetTimeout = common.platformTimeout(100);
|
||||
let didReceiveData = false;
|
||||
|
||||
const content = Buffer.alloc(writeSize, 0x44);
|
||||
const filepath = tmpdir.resolve('http2-large-write.tmp');
|
||||
fs.writeFileSync(filepath, content, 'binary');
|
||||
@@ -52,8 +51,10 @@ server.on('timeout', common.mustCallAtLeast(() => {
|
||||
}, 0));
|
||||
|
||||
server.listen(0, common.mustCall(() => {
|
||||
const client = http2.connect(`https://localhost:${server.address().port}`,
|
||||
{ rejectUnauthorized: false });
|
||||
const client = http2.connect(`https://localhost:${server.address().port}`, {
|
||||
rejectUnauthorized: false,
|
||||
settings: { initialWindowSize: 65535 },
|
||||
});
|
||||
|
||||
const req = client.request({ ':path': '/' });
|
||||
req.end();
|
||||
|
||||
@@ -23,7 +23,6 @@ const minReadSize = 500000;
|
||||
const serverTimeout = common.platformTimeout(500);
|
||||
let offsetTimeout = common.platformTimeout(100);
|
||||
let didReceiveData = false;
|
||||
|
||||
const server = http2.createSecureServer({
|
||||
key: fixtures.readKey('agent1-key.pem'),
|
||||
cert: fixtures.readKey('agent1-cert.pem'),
|
||||
@@ -49,8 +48,10 @@ server.setTimeout(serverTimeout);
|
||||
server.on('timeout', onTimeout);
|
||||
|
||||
server.listen(0, common.mustCall(() => {
|
||||
const client = http2.connect(`https://localhost:${server.address().port}`,
|
||||
{ rejectUnauthorized: false });
|
||||
const client = http2.connect(`https://localhost:${server.address().port}`, {
|
||||
rejectUnauthorized: false,
|
||||
settings: { initialWindowSize: 65535 },
|
||||
});
|
||||
|
||||
const req = client.request({ ':path': '/' });
|
||||
req.end();
|
||||
|
||||
@@ -26,7 +26,9 @@ const assert = require('assert');
|
||||
family: 4,
|
||||
localPort: common.PORT,
|
||||
rejectUnauthorized: false,
|
||||
}, common.mustCall(() => {
|
||||
agent: false,
|
||||
}, common.mustCall((res) => {
|
||||
res.resume();
|
||||
assert.strictEqual(req.socket.localPort, common.PORT);
|
||||
assert.strictEqual(req.socket.remotePort, port);
|
||||
}));
|
||||
|
||||
Reference in new issue
Block a user