test: harden test-gc-http-client-timeout
* decrease number of requests 500 -> 300 * extract 'cb' to a file-local function This should make test more reliable and less resource intensive. PR-URL: https://github.com/nodejs/node/pull/23184 Refs: https://github.com/nodejs/node/issues/23066 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
6696354dba
commit
69a422bba7
@ -3,7 +3,7 @@
|
|||||||
// just like test-gc-http-client.js,
|
// just like test-gc-http-client.js,
|
||||||
// but with a timeout set
|
// but with a timeout set
|
||||||
|
|
||||||
require('../common');
|
const common = require('../common');
|
||||||
const onGC = require('../common/ongc');
|
const onGC = require('../common/ongc');
|
||||||
|
|
||||||
function serverHandler(req, res) {
|
function serverHandler(req, res) {
|
||||||
@ -15,7 +15,7 @@ function serverHandler(req, res) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const http = require('http');
|
const http = require('http');
|
||||||
const todo = 550;
|
const todo = 300;
|
||||||
let done = 0;
|
let done = 0;
|
||||||
let count = 0;
|
let count = 0;
|
||||||
let countGC = 0;
|
let countGC = 0;
|
||||||
@ -23,31 +23,24 @@ let countGC = 0;
|
|||||||
console.log(`We should do ${todo} requests`);
|
console.log(`We should do ${todo} requests`);
|
||||||
|
|
||||||
const server = http.createServer(serverHandler);
|
const server = http.createServer(serverHandler);
|
||||||
server.listen(0, getall);
|
server.listen(0, common.mustCall(getall));
|
||||||
|
|
||||||
function getall() {
|
function getall() {
|
||||||
if (count >= todo)
|
if (count >= todo)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
(function() {
|
const req = http.get({
|
||||||
function cb(res) {
|
hostname: 'localhost',
|
||||||
res.resume();
|
pathname: '/',
|
||||||
done += 1;
|
port: server.address().port
|
||||||
}
|
}, cb);
|
||||||
|
|
||||||
const req = http.get({
|
req.setTimeout(10, function() {
|
||||||
hostname: 'localhost',
|
console.log('timeout (expected)');
|
||||||
pathname: '/',
|
});
|
||||||
port: server.address().port
|
|
||||||
}, cb);
|
|
||||||
|
|
||||||
req.setTimeout(10, function() {
|
count++;
|
||||||
console.log('timeout (expected)');
|
onGC(req, { ongc });
|
||||||
});
|
|
||||||
|
|
||||||
count++;
|
|
||||||
onGC(req, { ongc });
|
|
||||||
})();
|
|
||||||
|
|
||||||
setImmediate(getall);
|
setImmediate(getall);
|
||||||
}
|
}
|
||||||
@ -55,6 +48,11 @@ function getall() {
|
|||||||
for (let i = 0; i < 10; i++)
|
for (let i = 0; i < 10; i++)
|
||||||
getall();
|
getall();
|
||||||
|
|
||||||
|
function cb(res) {
|
||||||
|
res.resume();
|
||||||
|
done += 1;
|
||||||
|
}
|
||||||
|
|
||||||
function ongc() {
|
function ongc() {
|
||||||
countGC++;
|
countGC++;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user