From 1f88cbd6209f7daba61306f028d25b7d753ce685 Mon Sep 17 00:00:00 2001 From: realwakka Date: Sun, 4 Jun 2017 14:03:11 +0900 Subject: [PATCH] test: refactor test-http-server-keep-alive-timeout Make the same reliability changes that were applied to the https test in ce5745bf92f586c58366e9f738441d69118f2c18. Refs: https://github.com/nodejs/node/pull/13312 PR-URL: https://github.com/nodejs/node/pull/13448 Reviewed-By: Rich Trott Reviewed-By: Luigi Pinca Reviewed-By: Refael Ackermann Reviewed-By: James M Snell Reviewed-By: Alexey Orlenko --- .../test-http-server-keep-alive-timeout.js | 38 +++++-------------- 1 file changed, 10 insertions(+), 28 deletions(-) diff --git a/test/parallel/test-http-server-keep-alive-timeout.js b/test/parallel/test-http-server-keep-alive-timeout.js index 579a5a15e66c1a..dace64e4d02559 100644 --- a/test/parallel/test-http-server-keep-alive-timeout.js +++ b/test/parallel/test-http-server-keep-alive-timeout.js @@ -20,24 +20,20 @@ function run() { } test(function serverEndKeepAliveTimeoutWithPipeline(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 = http.createServer((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 = { @@ -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 /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 = http.createServer((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 = { @@ -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 /3 HTTP/1.1\r\nHost: localhost\r\n\r\n'); }); - setTimeout(() => { - server.close(); - if (socket.destroyed) destroyedSockets++; - cb(); - }, 1000); })); });