test: backoff client connection rates

We were being very aggressive in our connection creations, resulting
in the pipeline flood detection to drop us. Relax how fast we're
creating these connections so the gc can run all its tests.
This commit is contained in:
Timothy J Fontaine 2014-02-24 10:20:30 -08:00
parent dbae8b569f
commit af1418325b
5 changed files with 129 additions and 95 deletions

View File

@ -22,25 +22,31 @@ var server = http.createServer(serverHandler);
server.listen(PORT, getall);
function getall() {
for (var i = 0; i < todo; i++) {
(function(){
function cb(res) {
done+=1;
statusLater();
}
if (count >= todo)
return;
var req = http.get({
hostname: 'localhost',
pathname: '/',
port: PORT
}, cb).on('error', cb);
(function(){
function cb(res) {
done+=1;
statusLater();
}
count++;
weak(req, afterGC);
})()
}
var req = http.get({
hostname: 'localhost',
pathname: '/',
port: PORT
}, cb).on('error', cb);
count++;
weak(req, afterGC);
})()
setImmediate(getall);
}
for (var i = 0; i < 10; i++)
getall();
function afterGC(){
countGC ++;
}

View File

@ -2,6 +2,7 @@
// but with an on('error') handler that does nothing.
function serverHandler(req, res) {
req.resume();
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}
@ -23,28 +24,35 @@ var server = http.createServer(serverHandler);
server.listen(PORT, getall);
function getall() {
for (var i = 0; i < todo; i++) {
(function(){
function cb(res) {
done+=1;
statusLater();
}
function onerror(er) {
throw er;
}
if (count >= todo)
return;
var req = http.get({
hostname: 'localhost',
pathname: '/',
port: PORT
}, cb).on('error', onerror);
(function(){
function cb(res) {
res.resume();
done+=1;
statusLater();
}
function onerror(er) {
throw er;
}
count++;
weak(req, afterGC);
})()
}
var req = http.get({
hostname: 'localhost',
pathname: '/',
port: PORT
}, cb).on('error', onerror);
count++;
weak(req, afterGC);
})()
setImmediate(getall);
}
for (var i = 0; i < 10; i++)
getall();
function afterGC(){
countGC ++;
}
@ -62,7 +70,7 @@ function status() {
console.log('Collected: %d/%d', countGC, count);
if (done === todo) {
console.log('All should be collected now.');
assert(count === countGC);
assert.strictEqual(count, countGC);
process.exit(0);
}
}

View File

@ -3,6 +3,7 @@
function serverHandler(req, res) {
setTimeout(function () {
req.resume();
res.writeHead(200)
res.end('hello\n');
}, 100);
@ -25,29 +26,36 @@ var server = http.createServer(serverHandler);
server.listen(PORT, getall);
function getall() {
for (var i = 0; i < todo; i++) {
(function(){
function cb() {
done+=1;
statusLater();
}
if (count >= todo)
return;
var req = http.get({
hostname: 'localhost',
pathname: '/',
port: PORT
}, cb);
req.on('error', cb);
req.setTimeout(10, function(){
console.log('timeout (expected)')
});
(function(){
function cb(res) {
res.resume();
done+=1;
statusLater();
}
count++;
weak(req, afterGC);
})()
}
var req = http.get({
hostname: 'localhost',
pathname: '/',
port: PORT
}, cb);
req.on('error', cb);
req.setTimeout(10, function(){
console.log('timeout (expected)')
});
count++;
weak(req, afterGC);
})()
setImmediate(getall);
}
for(var i = 0; i < 10; i++)
getall();
function afterGC(){
countGC ++;
}

View File

@ -23,36 +23,38 @@ server.listen(PORT, getall);
function getall() {
for (var i = 0; i < todo; i++) {
(function(){
function cb(res) {
console.error('in cb')
done+=1;
res.on('end', statusLater);
}
if (count >= todo)
return;
var req = http.get({
hostname: 'localhost',
pathname: '/',
port: PORT
}, cb)
(function(){
function cb(res) {
res.resume();
console.error('in cb')
done+=1;
res.on('end', gc);
}
count++;
weak(req, afterGC);
})()
}
var req = http.get({
hostname: 'localhost',
pathname: '/',
port: PORT
}, cb)
count++;
weak(req, afterGC);
})()
setImmediate(getall);
}
for (var i = 0; i < 10; i++)
getall();
function afterGC(){
countGC ++;
}
var timer;
function statusLater() {
gc();
if (timer) clearTimeout(timer);
timer = setTimeout(status, 1);
}
setInterval(status, 1000).unref();
function status() {
gc();

View File

@ -3,7 +3,15 @@
function serverHandler(sock) {
sock.setTimeout(120000);
setTimeout(function () {
sock.resume();
var timer;
sock.on('close', function() {
clearTimeout(timer);
});
sock.on('error', function(err) {
assert.strictEqual(err.code, 'ECONNRESET');
});
timer = setTimeout(function () {
sock.end('hello\n');
}, 100);
}
@ -24,32 +32,34 @@ var server = net.createServer(serverHandler);
server.listen(PORT, getall);
function getall() {
for (var i = 0; i < todo; i++) {
(function(){
var req = net.connect(PORT, '127.0.0.1');
req.setTimeout(10, function() {
console.log('timeout (expected)')
req.destroy();
done++;
statusLater();
});
if (count >= todo)
return;
count++;
weak(req, afterGC);
})();
}
(function(){
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);
}
for (var i = 0; i < 10; i++)
getall();
function afterGC(){
countGC ++;
}
var timer;
function statusLater() {
gc();
if (timer) clearTimeout(timer);
timer = setTimeout(status, 1);
}
setInterval(status, 100).unref();
function status() {
gc();