From 625343705ab0b09ca5597a01d2030122f32a119e Mon Sep 17 00:00:00 2001 From: Francisco Gerardo Neri Andriano Date: Tue, 5 Dec 2017 20:58:36 -0600 Subject: [PATCH 1/2] test: update test-http-status-code to use countdown The test was changed to use countdown instead of validating if the index of the array of codes exceeded the size of the array. Also the validation that was before didn't allow to execute the last test, so the assert equal was to 5, and the last status in the array wasn't tested. The change was to assert 6 tests complete. Fixes: https://github.com/nodejs/node/issues/17169 --- test/parallel/test-http-status-code.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/parallel/test-http-status-code.js b/test/parallel/test-http-status-code.js index 802565f26bb697..f0c6251d47449d 100644 --- a/test/parallel/test-http-status-code.js +++ b/test/parallel/test-http-status-code.js @@ -23,6 +23,7 @@ require('../common'); const assert = require('assert'); const http = require('http'); +const Countdown = require('../common/countdown'); // Simple test of Node's HTTP ServerResponse.statusCode // ServerResponse.prototype.statusCode @@ -30,6 +31,7 @@ const http = require('http'); let testsComplete = 0; const tests = [200, 202, 300, 404, 451, 500]; let testIdx = 0; +const countdown = new Countdown(tests.length, () => s.close()); const s = http.createServer(function(req, res) { const t = tests[testIdx]; @@ -43,9 +45,6 @@ s.listen(0, nextTest); function nextTest() { - if (testIdx + 1 === tests.length) { - return s.close(); - } const test = tests[testIdx]; http.get({ port: s.address().port }, function(response) { @@ -55,7 +54,8 @@ function nextTest() { response.on('end', function() { testsComplete++; testIdx += 1; - nextTest(); + if (countdown.dec()) + nextTest(); }); response.resume(); }); @@ -63,5 +63,5 @@ function nextTest() { process.on('exit', function() { - assert.strictEqual(5, testsComplete); + assert.strictEqual(6, testsComplete); }); From 572889e397d99683d3088da0aafee7dca07b0108 Mon Sep 17 00:00:00 2001 From: Francisco Gerardo Neri Andriano Date: Wed, 6 Dec 2017 11:29:47 -0600 Subject: [PATCH 2/2] test: update test-http-status-code to use countdown The test was changed to use countdown instead of validating if the index of the array of codes exceeded the size of the array. Also the validation that was before didn't allow to execute the last test, so the assert equal was to 5, and the last status in the array wasn't tested. The change was to assert 6 tests complete. Variable testIdx to manage index in array removed, using array shift instead to manage the actual test. Variable testsComplete removed, not necessary, Countdown takes care of running right amount of tests Added a test variable that has the actual code for testing Fixes: https://github.com/nodejs/node/issues/17169 --- test/parallel/test-http-status-code.js | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/test/parallel/test-http-status-code.js b/test/parallel/test-http-status-code.js index f0c6251d47449d..246d22c131fe65 100644 --- a/test/parallel/test-http-status-code.js +++ b/test/parallel/test-http-status-code.js @@ -28,16 +28,14 @@ const Countdown = require('../common/countdown'); // Simple test of Node's HTTP ServerResponse.statusCode // ServerResponse.prototype.statusCode -let testsComplete = 0; const tests = [200, 202, 300, 404, 451, 500]; -let testIdx = 0; +let test; const countdown = new Countdown(tests.length, () => s.close()); const s = http.createServer(function(req, res) { - const t = tests[testIdx]; - res.writeHead(t, { 'Content-Type': 'text/plain' }); + res.writeHead(test, { 'Content-Type': 'text/plain' }); console.log(`--\nserver: statusCode after writeHead: ${res.statusCode}`); - assert.strictEqual(res.statusCode, t); + assert.strictEqual(res.statusCode, test); res.end('hello world\n'); }); @@ -45,23 +43,16 @@ s.listen(0, nextTest); function nextTest() { - const test = tests[testIdx]; + test = tests.shift(); http.get({ port: s.address().port }, function(response) { console.log(`client: expected status: ${test}`); console.log(`client: statusCode: ${response.statusCode}`); assert.strictEqual(response.statusCode, test); response.on('end', function() { - testsComplete++; - testIdx += 1; if (countdown.dec()) nextTest(); }); response.resume(); }); } - - -process.on('exit', function() { - assert.strictEqual(6, testsComplete); -});