Skip to content

Commit

Permalink
test: update test/parallel/test-http-pipe-fs.js to use countdown
Browse files Browse the repository at this point in the history
PR-URL: #17346
Reviewed-By: Jon Moss <me@jonathanmoss.me>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
chungngoops authored and addaleax committed Dec 1, 2017
1 parent 0f3fd79 commit fa07249
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions test/parallel/test-http-pipe-fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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');
}
});

0 comments on commit fa07249

Please sign in to comment.