test: update test-http-timeout to use countdown
PR-URL: https://github.com/nodejs/node/pull/17341 Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
This commit is contained in:
parent
e1054abea0
commit
996bfccd17
@ -23,24 +23,25 @@
|
|||||||
require('../common');
|
require('../common');
|
||||||
|
|
||||||
const http = require('http');
|
const http = require('http');
|
||||||
|
const Countdown = require('../common/countdown');
|
||||||
|
|
||||||
const server = http.createServer(function(req, res) {
|
const server = http.createServer(function(req, res) {
|
||||||
res.writeHead(200, { 'Content-Type': 'text/plain' });
|
res.writeHead(200, { 'Content-Type': 'text/plain' });
|
||||||
res.end('OK');
|
res.end('OK');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const MAX_COUNT = 11;
|
||||||
const agent = new http.Agent({ maxSockets: 1 });
|
const agent = new http.Agent({ maxSockets: 1 });
|
||||||
|
const countdown = new Countdown(MAX_COUNT, () => server.close());
|
||||||
|
|
||||||
server.listen(0, function() {
|
server.listen(0, function() {
|
||||||
|
|
||||||
for (let i = 0; i < 11; ++i) {
|
for (let i = 0; i < MAX_COUNT; ++i) {
|
||||||
createRequest().end();
|
createRequest().end();
|
||||||
}
|
}
|
||||||
|
|
||||||
function callback() {}
|
function callback() {}
|
||||||
|
|
||||||
let count = 0;
|
|
||||||
|
|
||||||
function createRequest() {
|
function createRequest() {
|
||||||
const req = http.request(
|
const req = http.request(
|
||||||
{ port: server.address().port, path: '/', agent: agent },
|
{ port: server.address().port, path: '/', agent: agent },
|
||||||
@ -48,11 +49,7 @@ server.listen(0, function() {
|
|||||||
req.clearTimeout(callback);
|
req.clearTimeout(callback);
|
||||||
|
|
||||||
res.on('end', function() {
|
res.on('end', function() {
|
||||||
count++;
|
countdown.dec();
|
||||||
|
|
||||||
if (count === 11) {
|
|
||||||
server.close();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
res.resume();
|
res.resume();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user