Skip to content

Commit 3ee4c1e

Browse files
chungngoopsgibfahn
authored andcommitted
test: update test/parallel/test-http-pipe-fs.js to use countdown
PR-URL: #17346 Reviewed-By: Jon Moss <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent 8908cd6 commit 3ee4c1e

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

test/parallel/test-http-pipe-fs.js

+21-21
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ const common = require('../common');
33
const http = require('http');
44
const fs = require('fs');
55
const path = require('path');
6+
const Countdown = require('../common/countdown');
7+
const NUMBER_OF_STREAMS = 2;
8+
9+
const countdown = new Countdown(NUMBER_OF_STREAMS, () => server.close());
610

711
common.refreshTmpDir();
812

@@ -18,27 +22,23 @@ const server = http.createServer(common.mustCall(function(req, res) {
1822
}, 2)).listen(0, function() {
1923
http.globalAgent.maxSockets = 1;
2024

21-
for (let i = 0; i < 2; ++i) {
22-
(function(i) {
23-
const req = http.request({
24-
port: server.address().port,
25-
method: 'POST',
26-
headers: {
27-
'Content-Length': 5
28-
}
29-
}, function(res) {
30-
res.on('end', function() {
31-
console.error(`res${i} end`);
32-
if (i === 2) {
33-
server.close();
34-
}
35-
});
36-
res.resume();
37-
});
38-
req.on('socket', function(s) {
39-
console.error(`req${i} start`);
25+
for (let i = 0; i < NUMBER_OF_STREAMS; ++i) {
26+
const req = http.request({
27+
port: server.address().port,
28+
method: 'POST',
29+
headers: {
30+
'Content-Length': 5
31+
}
32+
}, function(res) {
33+
res.on('end', function() {
34+
console.error(`res${i + 1} end`);
35+
countdown.dec();
4036
});
41-
req.end('12345');
42-
}(i + 1));
37+
res.resume();
38+
});
39+
req.on('socket', function(s) {
40+
console.error(`req${i + 1} start`);
41+
});
42+
req.end('12345');
4343
}
4444
});

0 commit comments

Comments
 (0)