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
|
|
|
|
|
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(sock) {
|
|
|
|
sock.setTimeout(120000);
|
2014-02-24 19:20:30 +01:00
|
|
|
sock.resume();
|
|
|
|
sock.on('close', function() {
|
|
|
|
clearTimeout(timer);
|
|
|
|
});
|
|
|
|
sock.on('error', function(err) {
|
|
|
|
assert.strictEqual(err.code, 'ECONNRESET');
|
|
|
|
});
|
2017-01-08 14:19:00 +01:00
|
|
|
const timer = setTimeout(function() {
|
2012-05-03 19:16:25 +02:00
|
|
|
sock.end('hello\n');
|
|
|
|
}, 100);
|
|
|
|
}
|
|
|
|
|
2016-01-13 21:42:45 +01:00
|
|
|
const net = require('net');
|
2017-02-08 15:35:58 +01:00
|
|
|
const weak = require(`./build/${common.buildType}/binding`);
|
2016-01-13 21:42:45 +01:00
|
|
|
const assert = require('assert');
|
|
|
|
const todo = 500;
|
|
|
|
let done = 0;
|
|
|
|
let count = 0;
|
|
|
|
let countGC = 0;
|
2012-05-03 19:16:25 +02:00
|
|
|
|
2017-04-28 03:06:42 +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 = net.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
|
|
|
|
2017-01-17 11:30:43 +01:00
|
|
|
const req = net.connect(server.address().port);
|
2016-07-13 01:47:32 +02:00
|
|
|
req.resume();
|
|
|
|
req.setTimeout(10, function() {
|
|
|
|
req.destroy();
|
|
|
|
done++;
|
|
|
|
global.gc();
|
|
|
|
});
|
2014-02-24 19:20:30 +01:00
|
|
|
|
2016-07-13 01:47:32 +02:00
|
|
|
count++;
|
|
|
|
weak(req, afterGC);
|
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
|
|
|
}
|
|
|
|
|
2014-02-24 19:20:30 +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
|
|
|
}
|