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
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
var http = require('http'),
|
|
|
|
weak = require('weak'),
|
|
|
|
done = 0,
|
|
|
|
count = 0,
|
|
|
|
countGC = 0,
|
2012-05-11 02:55:54 +02:00
|
|
|
todo = 550,
|
2015-02-22 03:47:04 +01:00
|
|
|
common = require('../common'),
|
2012-05-03 19:16:25 +02:00
|
|
|
assert = require('assert'),
|
|
|
|
PORT = common.PORT;
|
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
console.log('We should do ' + todo + ' requests');
|
2012-05-03 19:16:25 +02:00
|
|
|
|
|
|
|
var server = http.createServer(serverHandler);
|
|
|
|
server.listen(PORT, getall);
|
|
|
|
|
|
|
|
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
|
|
|
statusLater();
|
|
|
|
}
|
2012-05-03 19:16:25 +02:00
|
|
|
|
2014-02-24 19:20:30 +01:00
|
|
|
var req = http.get({
|
|
|
|
hostname: 'localhost',
|
|
|
|
pathname: '/',
|
|
|
|
port: PORT
|
|
|
|
}, 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
|
|
|
}
|
|
|
|
|
2015-08-19 01:32:07 +02:00
|
|
|
for (var i = 0; i < 10; i++)
|
2014-02-24 19:20:30 +01:00
|
|
|
getall();
|
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
function afterGC() {
|
2012-05-03 19:16:25 +02:00
|
|
|
countGC ++;
|
|
|
|
}
|
|
|
|
|
2012-05-04 19:32:42 +02:00
|
|
|
var timer;
|
2012-05-03 19:16:25 +02:00
|
|
|
function statusLater() {
|
2012-05-04 19:32:42 +02:00
|
|
|
gc();
|
|
|
|
if (timer) clearTimeout(timer);
|
|
|
|
timer = setTimeout(status, 1);
|
2012-05-03 19:16:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function status() {
|
|
|
|
gc();
|
|
|
|
console.log('Done: %d/%d', done, todo);
|
|
|
|
console.log('Collected: %d/%d', countGC, count);
|
|
|
|
if (done === todo) {
|
|
|
|
console.log('All should be collected now.');
|
|
|
|
assert(count === countGC);
|
|
|
|
process.exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|