Browse Source

test: refactor test-http-server-keep-alive-timeout

Make the same reliability changes that were applied to the https test in
ce5745bf92.

Refs: https://github.com/nodejs/node/pull/13312
PR-URL: https://github.com/nodejs/node/pull/13448
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
v6
realwakka 8 years ago
committed by Alexey Orlenko
parent
commit
1f9b1aa011
No known key found for this signature in database GPG Key ID: 81255941FDDB24ED
  1. 38
      test/parallel/test-http-server-keep-alive-timeout.js

38
test/parallel/test-http-server-keep-alive-timeout.js

@ -20,24 +20,20 @@ function run() {
} }
test(function serverEndKeepAliveTimeoutWithPipeline(cb) { test(function serverEndKeepAliveTimeoutWithPipeline(cb) {
let socket;
let destroyedSockets = 0;
let timeoutCount = 0;
let requestCount = 0; let requestCount = 0;
process.on('exit', () => { process.on('exit', () => {
assert.strictEqual(timeoutCount, 1);
assert.strictEqual(requestCount, 3); assert.strictEqual(requestCount, 3);
assert.strictEqual(destroyedSockets, 1);
}); });
const server = http.createServer((req, res) => { const server = http.createServer((req, res) => {
socket = req.socket;
requestCount++; requestCount++;
res.end(); res.end();
}); });
server.setTimeout(200, (socket) => { server.setTimeout(500, common.mustCall((socket) => {
timeoutCount++; // End this test and call `run()` for the next test (if any).
socket.destroy(); socket.destroy();
}); server.close();
cb();
}));
server.keepAliveTimeout = 50; server.keepAliveTimeout = 50;
server.listen(0, common.mustCall(() => { server.listen(0, common.mustCall(() => {
const options = { const options = {
@ -49,32 +45,23 @@ test(function serverEndKeepAliveTimeoutWithPipeline(cb) {
c.write('GET /2 HTTP/1.1\r\nHost: localhost\r\n\r\n'); 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'); 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) { test(function serverNoEndKeepAliveTimeoutWithPipeline(cb) {
let socket;
let destroyedSockets = 0;
let timeoutCount = 0;
let requestCount = 0; let requestCount = 0;
process.on('exit', () => { process.on('exit', () => {
assert.strictEqual(timeoutCount, 1);
assert.strictEqual(requestCount, 3); assert.strictEqual(requestCount, 3);
assert.strictEqual(destroyedSockets, 1);
}); });
const server = http.createServer((req, res) => { const server = http.createServer((req, res) => {
socket = req.socket;
requestCount++; requestCount++;
}); });
server.setTimeout(200, (socket) => { server.setTimeout(500, common.mustCall((socket) => {
timeoutCount++; // End this test and call `run()` for the next test (if any).
socket.destroy(); socket.destroy();
}); server.close();
cb();
}));
server.keepAliveTimeout = 50; server.keepAliveTimeout = 50;
server.listen(0, common.mustCall(() => { server.listen(0, common.mustCall(() => {
const options = { const options = {
@ -86,10 +73,5 @@ test(function serverNoEndKeepAliveTimeoutWithPipeline(cb) {
c.write('GET /2 HTTP/1.1\r\nHost: localhost\r\n\r\n'); 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'); c.write('GET /3 HTTP/1.1\r\nHost: localhost\r\n\r\n');
}); });
setTimeout(() => {
server.close();
if (socket.destroyed) destroyedSockets++;
cb();
}, 1000);
})); }));
}); });

Loading…
Cancel
Save