From ef25de749386c67f29c8494f85d8e1f36ff1c3e8 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 41508ed92d0fb7..fd625bb4acc541 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,27 +43,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'); } });