2015-05-19 19:00:06 +08:00
|
|
|
'use strict';
|
2012-05-04 01:16:25 +08:00
|
|
|
// just like test/gc/http-client.js,
|
|
|
|
// but aborting every connection that comes in.
|
|
|
|
|
2017-02-08 22:35:58 +08:00
|
|
|
const common = require('../common');
|
2016-07-19 04:33:42 +08:00
|
|
|
|
2012-05-04 01:16:25 +08:00
|
|
|
function serverHandler(req, res) {
|
|
|
|
res.connection.destroy();
|
|
|
|
}
|
|
|
|
|
2016-05-09 14:04:17 +08:00
|
|
|
const http = require('http');
|
2017-02-08 22:35:58 +08:00
|
|
|
const weak = require(`./build/${common.buildType}/binding`);
|
2016-01-14 04:42:45 +08:00
|
|
|
const todo = 500;
|
|
|
|
let done = 0;
|
|
|
|
let count = 0;
|
|
|
|
let countGC = 0;
|
2012-05-04 01:16:25 +08:00
|
|
|
|
2017-04-28 09:06:42 +08:00
|
|
|
console.log(`We should do ${todo} requests`);
|
2012-05-04 01:16:25 +08:00
|
|
|
|
2017-01-08 21:19:00 +08:00
|
|
|
const server = http.createServer(serverHandler);
|
2016-05-27 11:49:51 +08:00
|
|
|
server.listen(0, getall);
|
2012-05-04 01:16:25 +08:00
|
|
|
|
|
|
|
function getall() {
|
2014-02-25 02:20:30 +08:00
|
|
|
if (count >= todo)
|
|
|
|
return;
|
2012-05-04 01:16:25 +08:00
|
|
|
|
2015-05-19 19:00:06 +08:00
|
|
|
(function() {
|
2014-02-25 02:20:30 +08:00
|
|
|
function cb(res) {
|
2015-05-19 19:00:06 +08:00
|
|
|
done += 1;
|
2014-02-25 02:20:30 +08:00
|
|
|
}
|
2012-05-04 01:16:25 +08:00
|
|
|
|
2017-01-08 21:19:00 +08:00
|
|
|
const req = http.get({
|
2014-02-25 02:20:30 +08:00
|
|
|
hostname: 'localhost',
|
|
|
|
pathname: '/',
|
2016-05-27 11:49:51 +08:00
|
|
|
port: server.address().port
|
2014-02-25 02:20:30 +08:00
|
|
|
}, cb).on('error', cb);
|
|
|
|
|
|
|
|
count++;
|
|
|
|
weak(req, afterGC);
|
2015-05-19 19:00:06 +08:00
|
|
|
})();
|
2014-02-25 02:20:30 +08:00
|
|
|
|
|
|
|
setImmediate(getall);
|
2012-05-04 01:16:25 +08:00
|
|
|
}
|
|
|
|
|
2017-01-08 21:19:00 +08:00
|
|
|
for (let i = 0; i < 10; i++)
|
2014-02-25 02:20:30 +08:00
|
|
|
getall();
|
|
|
|
|
2015-05-19 19:00:06 +08:00
|
|
|
function afterGC() {
|
2016-02-04 04:27:40 +08:00
|
|
|
countGC++;
|
2012-05-04 01:16:25 +08:00
|
|
|
}
|
|
|
|
|
2017-02-08 22:33:52 +08:00
|
|
|
setInterval(status, 100).unref();
|
2012-05-04 01:16:25 +08:00
|
|
|
|
|
|
|
function status() {
|
2016-04-21 14:05:44 +08:00
|
|
|
global.gc();
|
2012-05-04 01:16:25 +08:00
|
|
|
console.log('Done: %d/%d', done, todo);
|
|
|
|
console.log('Collected: %d/%d', countGC, count);
|
2017-02-08 22:33:52 +08:00
|
|
|
if (countGC === todo) server.close();
|
2012-05-04 01:16:25 +08:00
|
|
|
}
|