2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2012-05-03 19:16:25 +02:00
|
|
|
// just like test/gc/http-client.js,
|
|
|
|
// but with a timeout set
|
|
|
|
|
2017-02-08 15:35:58 +01:00
|
|
|
const common = require('../common');
|
2016-07-18 22:33:42 +02:00
|
|
|
|
2012-05-03 19:16:25 +02:00
|
|
|
function serverHandler(req, res) {
|
2015-05-19 13:00:06 +02:00
|
|
|
setTimeout(function() {
|
2014-02-24 19:20:30 +01:00
|
|
|
req.resume();
|
2015-05-19 13:00:06 +02:00
|
|
|
res.writeHead(200);
|
2012-05-03 19:16:25 +02:00
|
|
|
res.end('hello\n');
|
|
|
|
}, 100);
|
|
|
|
}
|
|
|
|
|
2016-01-13 21:42:45 +01:00
|
|
|
const http = require('http');
|
2017-02-08 15:35:58 +01:00
|
|
|
const weak = require(`./build/${common.buildType}/binding`);
|
2016-01-13 21:42:45 +01:00
|
|
|
const todo = 550;
|
|
|
|
let done = 0;
|
|
|
|
let count = 0;
|
|
|
|
let countGC = 0;
|
2012-05-03 19:16:25 +02:00
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
console.log('We should do ' + todo + ' requests');
|
2012-05-03 19:16:25 +02:00
|
|
|
|
2017-01-08 14:19:00 +01:00
|
|
|
const server = http.createServer(serverHandler);
|
2016-05-27 05:49:51 +02:00
|
|
|
server.listen(0, getall);
|
2012-05-03 19:16:25 +02:00
|
|
|
|
|
|
|
function getall() {
|
2014-02-24 19:20:30 +01:00
|
|
|
if (count >= todo)
|
|
|
|
return;
|
2012-05-03 19:16:25 +02:00
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
(function() {
|
2014-02-24 19:20:30 +01:00
|
|
|
function cb(res) {
|
|
|
|
res.resume();
|
2015-05-19 13:00:06 +02:00
|
|
|
done += 1;
|
2014-02-24 19:20:30 +01:00
|
|
|
}
|
2012-05-03 19:16:25 +02:00
|
|
|
|
2017-01-08 14:19:00 +01:00
|
|
|
const req = http.get({
|
2014-02-24 19:20:30 +01:00
|
|
|
hostname: 'localhost',
|
|
|
|
pathname: '/',
|
2016-05-27 05:49:51 +02:00
|
|
|
port: server.address().port
|
2014-02-24 19:20:30 +01:00
|
|
|
}, cb);
|
|
|
|
req.on('error', cb);
|
2015-05-19 13:00:06 +02:00
|
|
|
req.setTimeout(10, function() {
|
|
|
|
console.log('timeout (expected)');
|
2014-02-24 19:20:30 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
count++;
|
|
|
|
weak(req, afterGC);
|
2015-05-19 13:00:06 +02:00
|
|
|
})();
|
2014-02-24 19:20:30 +01:00
|
|
|
|
|
|
|
setImmediate(getall);
|
2012-05-03 19:16:25 +02:00
|
|
|
}
|
|
|
|
|
2017-01-08 14:19:00 +01:00
|
|
|
for (let i = 0; i < 10; i++)
|
2014-02-24 19:20:30 +01:00
|
|
|
getall();
|
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
function afterGC() {
|
2016-02-03 21:27:40 +01:00
|
|
|
countGC++;
|
2012-05-03 19:16:25 +02:00
|
|
|
}
|
|
|
|
|
2017-02-08 15:33:52 +01:00
|
|
|
setInterval(status, 100).unref();
|
2012-05-03 19:16:25 +02:00
|
|
|
|
|
|
|
function status() {
|
2016-04-21 08:05:44 +02:00
|
|
|
global.gc();
|
2012-05-03 19:16:25 +02: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 19:16:25 +02:00
|
|
|
}
|