Skip to content

Commit dbcc378

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 7d55374 commit dbcc378

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
@@ -24,6 +24,10 @@ const common = require('../common');
2424
const http = require('http');
2525
const fs = require('fs');
2626
const path = require('path');
27+
const Countdown = require('../common/countdown');
28+
const NUMBER_OF_STREAMS = 2;
29+
30+
const countdown = new Countdown(NUMBER_OF_STREAMS, () => server.close());
2731

2832
common.refreshTmpDir();
2933

@@ -39,27 +43,23 @@ const server = http.createServer(common.mustCall(function(req, res) {
3943
}, 2)).listen(0, function() {
4044
http.globalAgent.maxSockets = 1;
4145

42-
for (let i = 0; i < 2; ++i) {
43-
(function(i) {
44-
const req = http.request({
45-
port: server.address().port,
46-
method: 'POST',
47-
headers: {
48-
'Content-Length': 5
49-
}
50-
}, function(res) {
51-
res.on('end', function() {
52-
console.error(`res${i} end`);
53-
if (i === 2) {
54-
server.close();
55-
}
56-
});
57-
res.resume();
58-
});
59-
req.on('socket', function(s) {
60-
console.error(`req${i} start`);
46+
for (let i = 0; i < NUMBER_OF_STREAMS; ++i) {
47+
const req = http.request({
48+
port: server.address().port,
49+
method: 'POST',
50+
headers: {
51+
'Content-Length': 5
52+
}
53+
}, function(res) {
54+
res.on('end', function() {
55+
console.error(`res${i + 1} end`);
56+
countdown.dec();
6157
});
62-
req.end('12345');
63-
}(i + 1));
58+
res.resume();
59+
});
60+
req.on('socket', function(s) {
61+
console.error(`req${i + 1} start`);
62+
});
63+
req.end('12345');
6464
}
6565
});

0 commit comments

Comments
 (0)