From 8365fc7d63b035227e688919785982a341b59f21 Mon Sep 17 00:00:00 2001 From: hmammedzadeh Date: Sun, 3 Dec 2017 21:16:05 +0100 Subject: [PATCH 1/3] refac: refactor test-http-response-multiheaders to use countdown --- test/parallel/test-http-response-multiheaders.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-http-response-multiheaders.js b/test/parallel/test-http-response-multiheaders.js index ccfc31192d3770..4ef57e82d3a687 100644 --- a/test/parallel/test-http-response-multiheaders.js +++ b/test/parallel/test-http-response-multiheaders.js @@ -3,6 +3,7 @@ const common = require('../common'); const http = require('http'); const assert = require('assert'); +const Countdown = require('../common/countdown'); // Test that certain response header fields do not repeat. // 'content-length' should also be in this list but it is @@ -47,7 +48,7 @@ const server = http.createServer(function(req, res) { }); server.listen(0, common.mustCall(function() { - let count = 0; + const countdown = new Countdown(2, () => server.close()); for (let n = 1; n <= 2; n++) { // this runs twice, the first time, the server will use // setHeader, the second time it uses writeHead. The @@ -58,7 +59,7 @@ server.listen(0, common.mustCall(function() { http.get( { port: this.address().port, headers: { 'x-num': n } }, common.mustCall(function(res) { - if (++count === 2) server.close(); + countdown.dec(); for (const name of norepeat) { assert.strictEqual(res.headers[name], 'A'); } From 6e9f719391e3bc6d592b19aa00651d450b4385b7 Mon Sep 17 00:00:00 2001 From: hmammedzadeh Date: Sun, 3 Dec 2017 21:16:52 +0100 Subject: [PATCH 2/3] refac: introduce a variable to store count of runs --- test/parallel/test-http-response-multiheaders.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-http-response-multiheaders.js b/test/parallel/test-http-response-multiheaders.js index 4ef57e82d3a687..b5a06544d41b93 100644 --- a/test/parallel/test-http-response-multiheaders.js +++ b/test/parallel/test-http-response-multiheaders.js @@ -48,8 +48,9 @@ const server = http.createServer(function(req, res) { }); server.listen(0, common.mustCall(function() { - const countdown = new Countdown(2, () => server.close()); - for (let n = 1; n <= 2; n++) { + const runCount = 2; + const countdown = new Countdown(runCount, () => server.close()); + for (let n = 1; n <= runCount; n++) { // this runs twice, the first time, the server will use // setHeader, the second time it uses writeHead. The // result on the client side should be the same in From afacc3e0f081fb8e29fe667abd0ee9720fafb36f Mon Sep 17 00:00:00 2001 From: hmammedzadeh Date: Mon, 4 Dec 2017 23:46:15 +0100 Subject: [PATCH 3/3] refac: move a variable outside of server listener --- test/parallel/test-http-response-multiheaders.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-http-response-multiheaders.js b/test/parallel/test-http-response-multiheaders.js index b5a06544d41b93..f9429cff934276 100644 --- a/test/parallel/test-http-response-multiheaders.js +++ b/test/parallel/test-http-response-multiheaders.js @@ -28,6 +28,7 @@ const norepeat = [ 'age', 'expires' ]; +const runCount = 2; const server = http.createServer(function(req, res) { const num = req.headers['x-num']; @@ -48,7 +49,6 @@ const server = http.createServer(function(req, res) { }); server.listen(0, common.mustCall(function() { - const runCount = 2; const countdown = new Countdown(runCount, () => server.close()); for (let n = 1; n <= runCount; n++) { // this runs twice, the first time, the server will use