Browse Source

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.
v0.11.12-release
Timothy J Fontaine 11 years ago
parent
commit
af1418325b
  1. 10
      test/gc/test-http-client-connaborted.js
  2. 14
      test/gc/test-http-client-onerror.js
  3. 14
      test/gc/test-http-client-timeout.js
  4. 20
      test/gc/test-http-client.js
  5. 32
      test/gc/test-net-timeout.js

10
test/gc/test-http-client-connaborted.js

@ -22,7 +22,9 @@ var server = http.createServer(serverHandler);
server.listen(PORT, getall); server.listen(PORT, getall);
function getall() { function getall() {
for (var i = 0; i < todo; i++) { if (count >= todo)
return;
(function(){ (function(){
function cb(res) { function cb(res) {
done+=1; done+=1;
@ -38,8 +40,12 @@ function getall() {
count++; count++;
weak(req, afterGC); weak(req, afterGC);
})() })()
setImmediate(getall);
} }
}
for (var i = 0; i < 10; i++)
getall();
function afterGC(){ function afterGC(){
countGC ++; countGC ++;

14
test/gc/test-http-client-onerror.js

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

14
test/gc/test-http-client-timeout.js

@ -3,6 +3,7 @@
function serverHandler(req, res) { function serverHandler(req, res) {
setTimeout(function () { setTimeout(function () {
req.resume();
res.writeHead(200) res.writeHead(200)
res.end('hello\n'); res.end('hello\n');
}, 100); }, 100);
@ -25,9 +26,12 @@ var server = http.createServer(serverHandler);
server.listen(PORT, getall); server.listen(PORT, getall);
function getall() { function getall() {
for (var i = 0; i < todo; i++) { if (count >= todo)
return;
(function(){ (function(){
function cb() { function cb(res) {
res.resume();
done+=1; done+=1;
statusLater(); statusLater();
} }
@ -45,8 +49,12 @@ function getall() {
count++; count++;
weak(req, afterGC); weak(req, afterGC);
})() })()
setImmediate(getall);
} }
}
for(var i = 0; i < 10; i++)
getall();
function afterGC(){ function afterGC(){
countGC ++; countGC ++;

20
test/gc/test-http-client.js

@ -23,12 +23,15 @@ server.listen(PORT, getall);
function getall() { function getall() {
for (var i = 0; i < todo; i++) { if (count >= todo)
return;
(function(){ (function(){
function cb(res) { function cb(res) {
res.resume();
console.error('in cb') console.error('in cb')
done+=1; done+=1;
res.on('end', statusLater); res.on('end', gc);
} }
var req = http.get({ var req = http.get({
@ -40,19 +43,18 @@ function getall() {
count++; count++;
weak(req, afterGC); weak(req, afterGC);
})() })()
}
setImmediate(getall);
} }
for (var i = 0; i < 10; i++)
getall();
function afterGC(){ function afterGC(){
countGC ++; countGC ++;
} }
var timer; setInterval(status, 1000).unref();
function statusLater() {
gc();
if (timer) clearTimeout(timer);
timer = setTimeout(status, 1);
}
function status() { function status() {
gc(); gc();

32
test/gc/test-net-timeout.js

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

Loading…
Cancel
Save