From 3ee4c1e1492814f5d47ca83d3aac727a38a7d206 Mon Sep 17 00:00:00 2001 From: ChungNgoops Date: Mon, 27 Nov 2017 17:18:45 +0700 Subject: [PATCH] test: update test/parallel/test-http-pipe-fs.js to use countdown PR-URL: https://github.com/nodejs/node/pull/17346 Reviewed-By: Jon Moss Reviewed-By: Anna Henningsen --- test/parallel/test-http-pipe-fs.js | 42 +++++++++++++++--------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/test/parallel/test-http-pipe-fs.js b/test/parallel/test-http-pipe-fs.js index 4dc86a2022527e..11af232454ffb5 100644 --- a/test/parallel/test-http-pipe-fs.js +++ b/test/parallel/test-http-pipe-fs.js @@ -3,6 +3,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(); @@ -18,27 +22,23 @@ const server = http.createServer(common.mustCall(function(req, res) { }, 2)).listen(0, function() { http.globalAgent.maxSockets = 1; - for (let i = 0; i < 2; ++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`); - if (i === 2) { - server.close(); - } - }); - res.resume(); - }); - req.on('socket', function(s) { - console.error(`req${i} start`); + for (let i = 0; i < NUMBER_OF_STREAMS; ++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 + 1} end`); + countdown.dec(); }); - req.end('12345'); - }(i + 1)); + res.resume(); + }); + req.on('socket', function(s) { + console.error(`req${i + 1} start`); + }); + req.end('12345'); } });