Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 10 additions & 28 deletions test/parallel/test-https-server-keep-alive-timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,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 = {
Expand All @@ -60,32 +56,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 = {
Expand All @@ -98,10 +85,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);
}));
});