From 16e1c01a1f19ad8a046c56a15ba8aa2fc7ef8a96 Mon Sep 17 00:00:00 2001 From: TomerOmri Date: Wed, 6 Dec 2017 21:13:37 +0200 Subject: [PATCH 1/9] Edit countdown replace response counter --- test/parallel/test-http-expect-handling.js | 6 +++++- test/parallel/test-http-keepalive-client.js | 2 +- test/parallel/test-http-should-keep-alive.js | 11 +++++++---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/test/parallel/test-http-expect-handling.js b/test/parallel/test-http-expect-handling.js index fd1f244979459f..e9e0f2c948825c 100644 --- a/test/parallel/test-http-expect-handling.js +++ b/test/parallel/test-http-expect-handling.js @@ -3,6 +3,7 @@ const common = require('../common'); const assert = require('assert'); const http = require('http'); +const Countdown = require('../common/countdown'); const tests = [417, 417]; @@ -13,8 +14,10 @@ const s = http.createServer(function(req, res) { throw new Error('this should never be executed'); }); -s.listen(0, nextTest); + +s.listen(0, nextTest); +const countdown = new Countdown(tests.length, () => s.close() ); function nextTest() { const options = { port: s.address().port, @@ -43,6 +46,7 @@ function nextTest() { response.on('end', function() { testsComplete++; testIdx++; + countdown.dec(); nextTest(); }); response.resume(); diff --git a/test/parallel/test-http-keepalive-client.js b/test/parallel/test-http-keepalive-client.js index 5a9277feee9ae6..0145e431913e54 100644 --- a/test/parallel/test-http-keepalive-client.js +++ b/test/parallel/test-http-keepalive-client.js @@ -22,7 +22,7 @@ 'use strict'; require('../common'); const assert = require('assert'); - +const Countdown = require('../common/countdown'); const http = require('http'); diff --git a/test/parallel/test-http-should-keep-alive.js b/test/parallel/test-http-should-keep-alive.js index dd4709d6946a84..a37184196e39bf 100644 --- a/test/parallel/test-http-should-keep-alive.js +++ b/test/parallel/test-http-should-keep-alive.js @@ -24,6 +24,8 @@ require('../common'); const assert = require('assert'); const http = require('http'); const net = require('net'); +const common = require('../common'); +const Countdown = require('../common/countdown'); const SERVER_RESPONSES = [ 'HTTP/1.0 200 ok\r\nContent-Length: 0\r\n\r\n', @@ -45,6 +47,8 @@ let requests = 0; let responses = 0; http.globalAgent.maxSockets = 5; +const countdown = new Countdown(SHOULD_KEEP_ALIVE.length , () => server.close()); + const server = net.createServer(function(socket) { socket.write(SERVER_RESPONSES[requests]); ++requests; @@ -56,18 +60,17 @@ const server = net.createServer(function(socket) { `${SERVER_RESPONSES[responses]} should ${ SHOULD_KEEP_ALIVE[responses] ? '' : 'not '}Keep-Alive`); ++responses; - if (responses < SHOULD_KEEP_ALIVE.length) { + countdown.dec(); + if (countdown.remaining) { makeRequest(); - } else { - server.close(); } res.resume(); }); } - makeRequest(); }); + process.on('exit', function() { assert.strictEqual(requests, SERVER_RESPONSES.length); assert.strictEqual(responses, SHOULD_KEEP_ALIVE.length); From 7c58d6d26eef336885aa53ba28693081e742f4bb Mon Sep 17 00:00:00 2001 From: TomerOmri Date: Wed, 6 Dec 2017 21:19:44 +0200 Subject: [PATCH 2/9] Revert files --- test/parallel/test-http-expect-handling.js | 8 ++------ test/parallel/test-http-keepalive-client.js | 4 ++-- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/test/parallel/test-http-expect-handling.js b/test/parallel/test-http-expect-handling.js index e9e0f2c948825c..dcaf8235f34441 100644 --- a/test/parallel/test-http-expect-handling.js +++ b/test/parallel/test-http-expect-handling.js @@ -3,7 +3,6 @@ const common = require('../common'); const assert = require('assert'); const http = require('http'); -const Countdown = require('../common/countdown'); const tests = [417, 417]; @@ -14,10 +13,8 @@ const s = http.createServer(function(req, res) { throw new Error('this should never be executed'); }); - - s.listen(0, nextTest); -const countdown = new Countdown(tests.length, () => s.close() ); + function nextTest() { const options = { port: s.address().port, @@ -46,7 +43,6 @@ function nextTest() { response.on('end', function() { testsComplete++; testIdx++; - countdown.dec(); nextTest(); }); response.resume(); @@ -56,4 +52,4 @@ function nextTest() { process.on('exit', function() { assert.strictEqual(2, testsComplete); -}); +}); \ No newline at end of file diff --git a/test/parallel/test-http-keepalive-client.js b/test/parallel/test-http-keepalive-client.js index 0145e431913e54..a3228aaeed5bd0 100644 --- a/test/parallel/test-http-keepalive-client.js +++ b/test/parallel/test-http-keepalive-client.js @@ -22,7 +22,7 @@ 'use strict'; require('../common'); const assert = require('assert'); -const Countdown = require('../common/countdown'); + const http = require('http'); @@ -91,4 +91,4 @@ function makeRequest(n) { process.on('exit', function() { assert.strictEqual(actualRequests, expectRequests); console.log('ok'); -}); +}); \ No newline at end of file From b7119649854849d41ead0479b35c7679b19f6eff Mon Sep 17 00:00:00 2001 From: TomerOmri Date: Wed, 6 Dec 2017 23:09:44 +0200 Subject: [PATCH 3/9] Fix countdown --- test/parallel/test-http-should-keep-alive.js | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/test/parallel/test-http-should-keep-alive.js b/test/parallel/test-http-should-keep-alive.js index a37184196e39bf..1d77e716eb290e 100644 --- a/test/parallel/test-http-should-keep-alive.js +++ b/test/parallel/test-http-should-keep-alive.js @@ -43,23 +43,20 @@ const SHOULD_KEEP_ALIVE = [ true, // HTTP/1.1, Connection: keep-alive false // HTTP/1.1, Connection: close ]; -let requests = 0; -let responses = 0; http.globalAgent.maxSockets = 5; const countdown = new Countdown(SHOULD_KEEP_ALIVE.length , () => server.close()); +let countdownIndexInc = SERVER_RESPONSES.length - countdown.remaining; const server = net.createServer(function(socket) { - socket.write(SERVER_RESPONSES[requests]); - ++requests; + socket.write(SERVER_RESPONSES[countdownIndexInc]); }).listen(0, function() { function makeRequest() { const req = http.get({ port: server.address().port }, function(res) { assert.strictEqual( - req.shouldKeepAlive, SHOULD_KEEP_ALIVE[responses], - `${SERVER_RESPONSES[responses]} should ${ - SHOULD_KEEP_ALIVE[responses] ? '' : 'not '}Keep-Alive`); - ++responses; + req.shouldKeepAlive, SHOULD_KEEP_ALIVE[countdownIndexInc], + `${SERVER_RESPONSES[countdownIndexInc]} should ${ + SHOULD_KEEP_ALIVE[countdownIndexInc] ? '' : 'not '}Keep-Alive`); countdown.dec(); if (countdown.remaining) { makeRequest(); @@ -70,8 +67,8 @@ const server = net.createServer(function(socket) { makeRequest(); }); - process.on('exit', function() { - assert.strictEqual(requests, SERVER_RESPONSES.length); - assert.strictEqual(responses, SHOULD_KEEP_ALIVE.length); + countdownIndexInc = SERVER_RESPONSES.length - countdown.remaining; + assert.strictEqual(countdownIndexInc, SERVER_RESPONSES.length); + assert.strictEqual(countdownIndexInc, SHOULD_KEEP_ALIVE.length); }); From c8c14abac401d03ee7e27c148d8eb722c599202e Mon Sep 17 00:00:00 2001 From: TomerOmri Date: Wed, 6 Dec 2017 23:12:46 +0200 Subject: [PATCH 4/9] Fix countdown --- test/parallel/test-http-expect-handling.js | 2 +- test/parallel/test-http-keepalive-client.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-http-expect-handling.js b/test/parallel/test-http-expect-handling.js index dcaf8235f34441..fd1f244979459f 100644 --- a/test/parallel/test-http-expect-handling.js +++ b/test/parallel/test-http-expect-handling.js @@ -52,4 +52,4 @@ function nextTest() { process.on('exit', function() { assert.strictEqual(2, testsComplete); -}); \ No newline at end of file +}); diff --git a/test/parallel/test-http-keepalive-client.js b/test/parallel/test-http-keepalive-client.js index a3228aaeed5bd0..5a9277feee9ae6 100644 --- a/test/parallel/test-http-keepalive-client.js +++ b/test/parallel/test-http-keepalive-client.js @@ -91,4 +91,4 @@ function makeRequest(n) { process.on('exit', function() { assert.strictEqual(actualRequests, expectRequests); console.log('ok'); -}); \ No newline at end of file +}); From 216cced6b63c01a6d3ce637943913eb431abdc80 Mon Sep 17 00:00:00 2001 From: TomerOmri Date: Wed, 6 Dec 2017 23:40:33 +0200 Subject: [PATCH 5/9] Fix- add function and remove assertequals --- test/parallel/test-http-should-keep-alive.js | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/test/parallel/test-http-should-keep-alive.js b/test/parallel/test-http-should-keep-alive.js index 1d77e716eb290e..b6421592654f2e 100644 --- a/test/parallel/test-http-should-keep-alive.js +++ b/test/parallel/test-http-should-keep-alive.js @@ -20,11 +20,10 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); const http = require('http'); const net = require('net'); -const common = require('../common'); const Countdown = require('../common/countdown'); const SERVER_RESPONSES = [ @@ -46,17 +45,18 @@ const SHOULD_KEEP_ALIVE = [ http.globalAgent.maxSockets = 5; const countdown = new Countdown(SHOULD_KEEP_ALIVE.length , () => server.close()); -let countdownIndexInc = SERVER_RESPONSES.length - countdown.remaining; + +const getCountdownIndex = () => SERVER_RESPONSES.length - countdown.remaining const server = net.createServer(function(socket) { - socket.write(SERVER_RESPONSES[countdownIndexInc]); + socket.write(SERVER_RESPONSES[getCountdownIndex()]); }).listen(0, function() { function makeRequest() { const req = http.get({ port: server.address().port }, function(res) { assert.strictEqual( - req.shouldKeepAlive, SHOULD_KEEP_ALIVE[countdownIndexInc], - `${SERVER_RESPONSES[countdownIndexInc]} should ${ - SHOULD_KEEP_ALIVE[countdownIndexInc] ? '' : 'not '}Keep-Alive`); + req.shouldKeepAlive, SHOULD_KEEP_ALIVE[getCountdownIndex()], + `${SERVER_RESPONSES[getCountdownIndex()]} should ${ + SHOULD_KEEP_ALIVE[getCountdownIndex()] ? '' : 'not '}Keep-Alive`); countdown.dec(); if (countdown.remaining) { makeRequest(); @@ -67,8 +67,3 @@ const server = net.createServer(function(socket) { makeRequest(); }); -process.on('exit', function() { - countdownIndexInc = SERVER_RESPONSES.length - countdown.remaining; - assert.strictEqual(countdownIndexInc, SERVER_RESPONSES.length); - assert.strictEqual(countdownIndexInc, SHOULD_KEEP_ALIVE.length); -}); From 47d82f52b918d0869c674125f6a3225119188adb Mon Sep 17 00:00:00 2001 From: TomerOmri Date: Wed, 6 Dec 2017 23:48:29 +0200 Subject: [PATCH 6/9] Fix- semi-colon and removes commo countdown --- test/parallel/test-http-should-keep-alive.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/parallel/test-http-should-keep-alive.js b/test/parallel/test-http-should-keep-alive.js index b6421592654f2e..710d13209c2dff 100644 --- a/test/parallel/test-http-should-keep-alive.js +++ b/test/parallel/test-http-should-keep-alive.js @@ -20,7 +20,6 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -const common = require('../common'); const assert = require('assert'); const http = require('http'); const net = require('net'); @@ -46,7 +45,7 @@ http.globalAgent.maxSockets = 5; const countdown = new Countdown(SHOULD_KEEP_ALIVE.length , () => server.close()); -const getCountdownIndex = () => SERVER_RESPONSES.length - countdown.remaining +const getCountdownIndex = () => SERVER_RESPONSES.length - countdown.remaining; const server = net.createServer(function(socket) { socket.write(SERVER_RESPONSES[getCountdownIndex()]); From 1f9a90d12cf4638fe34c827a4782a3c59eb88adf Mon Sep 17 00:00:00 2001 From: TomerOmri Date: Thu, 7 Dec 2017 08:56:05 +0200 Subject: [PATCH 7/9] fix require common --- test/parallel/test-http-should-keep-alive.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-http-should-keep-alive.js b/test/parallel/test-http-should-keep-alive.js index 710d13209c2dff..607c458de56f7f 100644 --- a/test/parallel/test-http-should-keep-alive.js +++ b/test/parallel/test-http-should-keep-alive.js @@ -20,6 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; +-require('../common'); const assert = require('assert'); const http = require('http'); const net = require('net'); @@ -45,7 +46,7 @@ http.globalAgent.maxSockets = 5; const countdown = new Countdown(SHOULD_KEEP_ALIVE.length , () => server.close()); -const getCountdownIndex = () => SERVER_RESPONSES.length - countdown.remaining; +const getCountdownIndex = () => SERVER_RESPONSES.length - countdown.remaining const server = net.createServer(function(socket) { socket.write(SERVER_RESPONSES[getCountdownIndex()]); @@ -65,4 +66,3 @@ const server = net.createServer(function(socket) { } makeRequest(); }); - From a94c818d006f671090f6714b006c4c6a61b577f3 Mon Sep 17 00:00:00 2001 From: TomerOmri Date: Thu, 7 Dec 2017 20:33:52 +0200 Subject: [PATCH 8/9] fix require and semicolon --- test/parallel/test-http-should-keep-alive.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-http-should-keep-alive.js b/test/parallel/test-http-should-keep-alive.js index 607c458de56f7f..46d26038945757 100644 --- a/test/parallel/test-http-should-keep-alive.js +++ b/test/parallel/test-http-should-keep-alive.js @@ -20,7 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; --require('../common'); +require('../common'); const assert = require('assert'); const http = require('http'); const net = require('net'); @@ -46,7 +46,7 @@ http.globalAgent.maxSockets = 5; const countdown = new Countdown(SHOULD_KEEP_ALIVE.length , () => server.close()); -const getCountdownIndex = () => SERVER_RESPONSES.length - countdown.remaining +const getCountdownIndex = () => SERVER_RESPONSES.length - countdown.remaining; const server = net.createServer(function(socket) { socket.write(SERVER_RESPONSES[getCountdownIndex()]); From b97270a32d744f8900f3cbeeab4b3cb2513951c0 Mon Sep 17 00:00:00 2001 From: tomz Date: Sat, 9 Dec 2017 09:32:13 +0200 Subject: [PATCH 9/9] delete space on countdown line --- test/parallel/test-http-should-keep-alive.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-http-should-keep-alive.js b/test/parallel/test-http-should-keep-alive.js index 46d26038945757..038af47ee4db97 100644 --- a/test/parallel/test-http-should-keep-alive.js +++ b/test/parallel/test-http-should-keep-alive.js @@ -44,7 +44,7 @@ const SHOULD_KEEP_ALIVE = [ ]; http.globalAgent.maxSockets = 5; -const countdown = new Countdown(SHOULD_KEEP_ALIVE.length , () => server.close()); +const countdown = new Countdown(SHOULD_KEEP_ALIVE.length, () => server.close()); const getCountdownIndex = () => SERVER_RESPONSES.length - countdown.remaining;