mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
test: improve test-https-server-keep-alive-timeout
The test is flaky under load. These changes greatly improve reliability. * Use a recurring interval to determine when the test should end rather than a timer. * Increase server timeout to 500ms to allow for events being delayed by system load Changing to an interval has the added benefit of reducing the test run time from over 2 seconds to under 1 second. Fixes: https://github.com/nodejs/node/issues/13307 PR-URL: https://github.com/nodejs/node/pull/13312 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
This commit is contained in:
1 parent
e9ae4aaaad
commit
1c7fbdc53b
1 file changed
+10
-28
@@ -26,24 +26,20 @@ function run() {
|
||||
}
|
||||
|
||||
test(function serverKeepAliveTimeoutWithPipeline(cb) {
|
||||
let socket;
|
||||
let destroyedSockets = 0;
|
||||
let timeoutCount = 0;
|
||||
let requestCount = 0;
|
||||
process.on('exit', function() {
|
||||
assert.strictEqual(timeoutCount, 1);
|
||||
assert.strictEqual(requestCount, 3);
|
||||
assert.strictEqual(destroyedSockets, 1);
|
||||
});
|
||||
const server = https.createServer(serverOptions, (req, res) => {
|
||||
socket = req.socket;
|
||||
requestCount++;
|
||||
res.end();
|
||||
});
|
||||
server.setTimeout(200, (socket) => {
|
||||
timeoutCount++;
|
||||
server.setTimeout(500, common.mustCall((socket) => {
|
||||
// End this test and call `run()` for the next test (if any).
|
||||
socket.destroy();
|
||||
});
|
||||
server.close();
|
||||
cb();
|
||||
}));
|
||||
server.keepAliveTimeout = 50;
|
||||
server.listen(0, common.mustCall(() => {
|
||||
const options = {
|
||||
@@ -56,32 +52,23 @@ test(function serverKeepAliveTimeoutWithPipeline(cb) {
|
||||
c.write('GET /2 HTTP/1.1\r\nHost: localhost\r\n\r\n');
|
||||
c.write('GET /3 HTTP/1.1\r\nHost: localhost\r\n\r\n');
|
||||
});
|
||||
setTimeout(() => {
|
||||
server.close();
|
||||
if (socket.destroyed) destroyedSockets++;
|
||||
cb();
|
||||
}, 1000);
|
||||
}));
|
||||
});
|
||||
|
||||
test(function serverNoEndKeepAliveTimeoutWithPipeline(cb) {
|
||||
let socket;
|
||||
let destroyedSockets = 0;
|
||||
let timeoutCount = 0;
|
||||
let requestCount = 0;
|
||||
process.on('exit', () => {
|
||||
assert.strictEqual(timeoutCount, 1);
|
||||
assert.strictEqual(requestCount, 3);
|
||||
assert.strictEqual(destroyedSockets, 1);
|
||||
});
|
||||
const server = https.createServer(serverOptions, (req, res) => {
|
||||
socket = req.socket;
|
||||
requestCount++;
|
||||
});
|
||||
server.setTimeout(200, (socket) => {
|
||||
timeoutCount++;
|
||||
server.setTimeout(500, common.mustCall((socket) => {
|
||||
// End this test and call `run()` for the next test (if any).
|
||||
socket.destroy();
|
||||
});
|
||||
server.close();
|
||||
cb();
|
||||
}));
|
||||
server.keepAliveTimeout = 50;
|
||||
server.listen(0, common.mustCall(() => {
|
||||
const options = {
|
||||
@@ -94,10 +81,5 @@ test(function serverNoEndKeepAliveTimeoutWithPipeline(cb) {
|
||||
c.write('GET /2 HTTP/1.1\r\nHost: localhost\r\n\r\n');
|
||||
c.write('GET /3 HTTP/1.1\r\nHost: localhost\r\n\r\n');
|
||||
});
|
||||
setTimeout(() => {
|
||||
server.close();
|
||||
if (socket && socket.destroyed) destroyedSockets++;
|
||||
cb();
|
||||
}, 1000);
|
||||
}));
|
||||
});
|
||||
Reference in new issue
Block a user