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 <me@jonathanmoss.me> Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
parent
0f3fd79ee9
commit
fa072499a5
@ -24,6 +24,10 @@ const common = require('../common');
|
|||||||
const http = require('http');
|
const http = require('http');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
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();
|
common.refreshTmpDir();
|
||||||
|
|
||||||
@ -39,8 +43,7 @@ const server = http.createServer(common.mustCall(function(req, res) {
|
|||||||
}, 2)).listen(0, function() {
|
}, 2)).listen(0, function() {
|
||||||
http.globalAgent.maxSockets = 1;
|
http.globalAgent.maxSockets = 1;
|
||||||
|
|
||||||
for (let i = 0; i < 2; ++i) {
|
for (let i = 0; i < NUMBER_OF_STREAMS; ++i) {
|
||||||
(function(i) {
|
|
||||||
const req = http.request({
|
const req = http.request({
|
||||||
port: server.address().port,
|
port: server.address().port,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@ -49,17 +52,14 @@ const server = http.createServer(common.mustCall(function(req, res) {
|
|||||||
}
|
}
|
||||||
}, function(res) {
|
}, function(res) {
|
||||||
res.on('end', function() {
|
res.on('end', function() {
|
||||||
console.error(`res${i} end`);
|
console.error(`res${i + 1} end`);
|
||||||
if (i === 2) {
|
countdown.dec();
|
||||||
server.close();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
res.resume();
|
res.resume();
|
||||||
});
|
});
|
||||||
req.on('socket', function(s) {
|
req.on('socket', function(s) {
|
||||||
console.error(`req${i} start`);
|
console.error(`req${i + 1} start`);
|
||||||
});
|
});
|
||||||
req.end('12345');
|
req.end('12345');
|
||||||
}(i + 1));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user