2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2018-07-27 13:36:35 +02:00
|
|
|
// Flags: --expose-gc
|
|
|
|
// just like test-gc-http-client.js,
|
2012-05-03 10:16:25 -07:00
|
|
|
// but with a timeout set
|
|
|
|
|
2018-08-21 13:38:59 -07:00
|
|
|
require('../common');
|
|
|
|
const onGC = require('../common/ongc');
|
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);
|
|
|
|
}
|
|
|
|
|
2016-01-13 21:42:45 +01:00
|
|
|
const http = require('http');
|
|
|
|
const todo = 550;
|
|
|
|
let done = 0;
|
|
|
|
let count = 0;
|
|
|
|
let countGC = 0;
|
2012-05-03 10:16:25 -07:00
|
|
|
|
2017-04-28 04:06:42 +03:00
|
|
|
console.log(`We should do ${todo} requests`);
|
2012-05-03 10:16:25 -07:00
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
const server = http.createServer(serverHandler);
|
2016-05-26 20:49:51 -07:00
|
|
|
server.listen(0, getall);
|
2012-05-03 10:16:25 -07:00
|
|
|
|
|
|
|
function getall() {
|
2014-02-24 10:20:30 -08:00
|
|
|
if (count >= todo)
|
|
|
|
return;
|
2012-05-03 10:16:25 -07:00
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
(function() {
|
2014-02-24 10:20:30 -08:00
|
|
|
function cb(res) {
|
|
|
|
res.resume();
|
2015-05-19 13:00:06 +02:00
|
|
|
done += 1;
|
2014-02-24 10:20:30 -08:00
|
|
|
}
|
2012-05-03 10:16:25 -07:00
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
const req = http.get({
|
2014-02-24 10:20:30 -08:00
|
|
|
hostname: 'localhost',
|
|
|
|
pathname: '/',
|
2016-05-26 20:49:51 -07:00
|
|
|
port: server.address().port
|
2014-02-24 10:20:30 -08:00
|
|
|
}, cb);
|
2018-08-08 10:51:16 +08:00
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
req.setTimeout(10, function() {
|
|
|
|
console.log('timeout (expected)');
|
2014-02-24 10:20:30 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
count++;
|
2018-08-21 13:38:59 -07:00
|
|
|
onGC(req, { ongc });
|
2015-05-19 13:00:06 +02:00
|
|
|
})();
|
2014-02-24 10:20:30 -08:00
|
|
|
|
|
|
|
setImmediate(getall);
|
2012-05-03 10:16:25 -07:00
|
|
|
}
|
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
for (let i = 0; i < 10; i++)
|
2014-02-24 10:20:30 -08:00
|
|
|
getall();
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-02-08 15:33:52 +01:00
|
|
|
setInterval(status, 100).unref();
|
2012-05-03 10:16:25 -07:00
|
|
|
|
|
|
|
function status() {
|
2016-04-20 23:05:44 -07:00
|
|
|
global.gc();
|
2012-05-03 10:16:25 -07:00
|
|
|
console.log('Done: %d/%d', done, todo);
|
|
|
|
console.log('Collected: %d/%d', countGC, count);
|
2017-02-08 15:33:52 +01:00
|
|
|
if (countGC === todo) server.close();
|
2012-05-03 10:16:25 -07:00
|
|
|
}
|