From ba5f74f3f8c5cb06525486020bc9757e06c35abf Mon Sep 17 00:00:00 2001 From: ChungNgoops Date: Mon, 27 Nov 2017 17:18:45 +0700 Subject: [PATCH 1/2] test: update test/parallel/test-http-pipe-fs.js to use countdown --- test/parallel/test-http-pipe-fs.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/parallel/test-http-pipe-fs.js b/test/parallel/test-http-pipe-fs.js index 41508ed92d0fb7..9fbf92f070e46e 100644 --- a/test/parallel/test-http-pipe-fs.js +++ b/test/parallel/test-http-pipe-fs.js @@ -24,6 +24,10 @@ const common = require('../common'); const http = require('http'); const fs = require('fs'); const path = require('path'); +const Countdown = require('../common/countdown'); +const NUMBER_OF_STREAMS = 2; + +const countdown = new Countdown(NUMBER_OF_STREAMS, () => server.close()); common.refreshTmpDir(); @@ -39,7 +43,7 @@ const server = http.createServer(common.mustCall(function(req, res) { }, 2)).listen(0, function() { http.globalAgent.maxSockets = 1; - for (let i = 0; i < 2; ++i) { + for (let i = 0; i < NUMBER_OF_STREAMS; ++i) { (function(i) { const req = http.request({ port: server.address().port, @@ -50,9 +54,7 @@ const server = http.createServer(common.mustCall(function(req, res) { }, function(res) { res.on('end', function() { console.error(`res${i} end`); - if (i === 2) { - server.close(); - } + countdown.dec(); }); res.resume(); }); From 87d76b5560b7d43a821413b1847f4d34ef5fe1a8 Mon Sep 17 00:00:00 2001 From: ChungNgoops Date: Mon, 27 Nov 2017 23:40:38 +0700 Subject: [PATCH 2/2] remove the unecessary IIFE --- test/parallel/test-http-pipe-fs.js | 34 ++++++++++++++---------------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/test/parallel/test-http-pipe-fs.js b/test/parallel/test-http-pipe-fs.js index 9fbf92f070e46e..fd625bb4acc541 100644 --- a/test/parallel/test-http-pipe-fs.js +++ b/test/parallel/test-http-pipe-fs.js @@ -44,24 +44,22 @@ const server = http.createServer(common.mustCall(function(req, res) { http.globalAgent.maxSockets = 1; for (let i = 0; i < NUMBER_OF_STREAMS; ++i) { - (function(i) { - const req = http.request({ - port: server.address().port, - method: 'POST', - headers: { - 'Content-Length': 5 - } - }, function(res) { - res.on('end', function() { - console.error(`res${i} end`); - countdown.dec(); - }); - res.resume(); + const req = http.request({ + port: server.address().port, + method: 'POST', + headers: { + 'Content-Length': 5 + } + }, function(res) { + res.on('end', function() { + console.error(`res${i + 1} end`); + countdown.dec(); }); - req.on('socket', function(s) { - console.error(`req${i} start`); - }); - req.end('12345'); - }(i + 1)); + res.resume(); + }); + req.on('socket', function(s) { + console.error(`req${i + 1} start`); + }); + req.end('12345'); } });