2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2012-05-03 19:16:25 +02:00
|
|
|
// just like test/gc/http-client-timeout.js,
|
|
|
|
// but using a net server/client instead
|
|
|
|
|
|
|
|
function serverHandler(sock) {
|
|
|
|
sock.setTimeout(120000);
|
2014-02-24 19:20:30 +01:00
|
|
|
sock.resume();
|
|
|
|
var timer;
|
|
|
|
sock.on('close', function() {
|
|
|
|
clearTimeout(timer);
|
|
|
|
});
|
|
|
|
sock.on('error', function(err) {
|
|
|
|
assert.strictEqual(err.code, 'ECONNRESET');
|
|
|
|
});
|
2015-05-19 13:00:06 +02:00
|
|
|
timer = setTimeout(function() {
|
2012-05-03 19:16:25 +02:00
|
|
|
sock.end('hello\n');
|
|
|
|
}, 100);
|
|
|
|
}
|
|
|
|
|
|
|
|
var net = require('net'),
|
|
|
|
weak = require('weak'),
|
|
|
|
done = 0,
|
|
|
|
count = 0,
|
|
|
|
countGC = 0,
|
2012-05-04 19:32:42 +02:00
|
|
|
todo = 500,
|
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 = net.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
|
|
|
var req = net.connect(PORT, '127.0.0.1');
|
|
|
|
req.resume();
|
|
|
|
req.setTimeout(10, function() {
|
|
|
|
//console.log('timeout (expected)')
|
|
|
|
req.destroy();
|
|
|
|
done++;
|
|
|
|
gc();
|
|
|
|
});
|
|
|
|
|
|
|
|
count++;
|
|
|
|
weak(req, afterGC);
|
|
|
|
})();
|
|
|
|
|
|
|
|
setImmediate(getall);
|
2012-05-03 19:16:25 +02:00
|
|
|
}
|
|
|
|
|
2014-02-24 19:20:30 +01:00
|
|
|
for (var i = 0; i < 10; i++)
|
|
|
|
getall();
|
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
function afterGC() {
|
2012-05-03 19:16:25 +02:00
|
|
|
countGC ++;
|
|
|
|
}
|
|
|
|
|
2014-02-24 19:20:30 +01:00
|
|
|
setInterval(status, 100).unref();
|
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) {
|
2012-06-13 02:49:33 +02:00
|
|
|
/* Give libuv some time to make close callbacks. */
|
|
|
|
setTimeout(function() {
|
|
|
|
gc();
|
|
|
|
console.log('All should be collected now.');
|
|
|
|
console.log('Collected: %d/%d', countGC, count);
|
|
|
|
assert(count === countGC);
|
|
|
|
process.exit(0);
|
|
|
|
}, 200);
|
2012-05-03 19:16:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|