2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2018-07-27 13:36:35 +02:00
|
|
|
// Flags: --expose-gc
|
2023-06-06 17:42:42 +02:00
|
|
|
// Like test-gc-http-client.js, but with a timeout set.
|
2012-05-03 10:16:25 -07:00
|
|
|
|
2018-09-30 22:04:14 +03:00
|
|
|
const common = require('../common');
|
2024-08-13 18:28:21 +08:00
|
|
|
const { onGC } = require('../common/gc');
|
2022-04-19 15:36:57 +02:00
|
|
|
const http = require('http');
|
2016-07-19 02:03:42 +05:30
|
|
|
|
2012-05-03 10:16:25 -07:00
|
|
|
function serverHandler(req, res) {
|
2015-05-19 13:00:06 +02:00
|
|
|
setTimeout(function() {
|
2014-02-24 10:20:30 -08:00
|
|
|
req.resume();
|
2015-05-19 13:00:06 +02:00
|
|
|
res.writeHead(200);
|
2012-05-03 10:16:25 -07:00
|
|
|
res.end('hello\n');
|
|
|
|
}, 100);
|
|
|
|
}
|
|
|
|
|
2023-06-06 17:42:42 +02:00
|
|
|
const numRequests = 128;
|
2016-01-13 21:42:45 +01:00
|
|
|
let done = 0;
|
|
|
|
let countGC = 0;
|
2012-05-03 10:16:25 -07:00
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
const server = http.createServer(serverHandler);
|
2023-06-06 17:42:42 +02:00
|
|
|
server.listen(0, common.mustCall(() => {
|
|
|
|
getAll(numRequests);
|
|
|
|
}));
|
2012-05-03 10:16:25 -07:00
|
|
|
|
2022-08-07 20:44:25 +08:00
|
|
|
function getAll(requestsRemaining) {
|
|
|
|
if (requestsRemaining <= 0)
|
|
|
|
return;
|
|
|
|
|
2018-09-30 22:04:14 +03:00
|
|
|
const req = http.get({
|
|
|
|
hostname: 'localhost',
|
|
|
|
pathname: '/',
|
|
|
|
port: server.address().port
|
|
|
|
}, cb);
|
2012-05-03 10:16:25 -07:00
|
|
|
|
2022-04-19 15:36:57 +02:00
|
|
|
req.setTimeout(10, common.mustCall());
|
2018-08-08 10:51:16 +08:00
|
|
|
|
2018-09-30 22:04:14 +03:00
|
|
|
onGC(req, { ongc });
|
2014-02-24 10:20:30 -08:00
|
|
|
|
2022-08-07 20:44:25 +08:00
|
|
|
setImmediate(getAll, requestsRemaining - 1);
|
2012-05-03 10:16:25 -07:00
|
|
|
}
|
|
|
|
|
2018-09-30 22:04:14 +03:00
|
|
|
function cb(res) {
|
|
|
|
res.resume();
|
|
|
|
done += 1;
|
|
|
|
}
|
|
|
|
|
2018-07-27 13:36:35 +02:00
|
|
|
function ongc() {
|
2016-02-03 12:27:40 -08:00
|
|
|
countGC++;
|
2012-05-03 10:16:25 -07:00
|
|
|
}
|
|
|
|
|
2022-04-19 15:36:57 +02:00
|
|
|
setImmediate(status);
|
2012-05-03 10:16:25 -07:00
|
|
|
|
|
|
|
function status() {
|
2022-04-19 15:36:57 +02:00
|
|
|
if (done > 0) {
|
|
|
|
global.gc();
|
2023-06-06 17:42:42 +02:00
|
|
|
console.log(`done/collected/total: ${done}/${countGC}/${numRequests}`);
|
|
|
|
if (countGC === numRequests) {
|
2022-04-19 15:36:57 +02:00
|
|
|
server.close();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setImmediate(status);
|
2012-05-03 10:16:25 -07:00
|
|
|
}
|