From af1418325bac37f70b57580eec98ee211e11c2dd Mon Sep 17 00:00:00 2001 From: Timothy J Fontaine Date: Mon, 24 Feb 2014 10:20:30 -0800 Subject: [PATCH] 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. --- test/gc/test-http-client-connaborted.js | 36 ++++++++++-------- test/gc/test-http-client-onerror.js | 46 +++++++++++++---------- test/gc/test-http-client-timeout.js | 46 +++++++++++++---------- test/gc/test-http-client.js | 46 ++++++++++++----------- test/gc/test-net-timeout.js | 50 +++++++++++++++---------- 5 files changed, 129 insertions(+), 95 deletions(-) diff --git a/test/gc/test-http-client-connaborted.js b/test/gc/test-http-client-connaborted.js index 80ac055109..4fbb429298 100644 --- a/test/gc/test-http-client-connaborted.js +++ b/test/gc/test-http-client-connaborted.js @@ -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 ++; } diff --git a/test/gc/test-http-client-onerror.js b/test/gc/test-http-client-onerror.js index 6bea7c000d..80a3fcf5b6 100644 --- a/test/gc/test-http-client-onerror.js +++ b/test/gc/test-http-client-onerror.js @@ -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); } } diff --git a/test/gc/test-http-client-timeout.js b/test/gc/test-http-client-timeout.js index 6d705b47eb..99a97d73b7 100644 --- a/test/gc/test-http-client-timeout.js +++ b/test/gc/test-http-client-timeout.js @@ -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 ++; } diff --git a/test/gc/test-http-client.js b/test/gc/test-http-client.js index 33be9ea15c..4c64bbadbb 100644 --- a/test/gc/test-http-client.js +++ b/test/gc/test-http-client.js @@ -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(); diff --git a/test/gc/test-net-timeout.js b/test/gc/test-net-timeout.js index 91d314b03d..5d2387dc74 100644 --- a/test/gc/test-net-timeout.js +++ b/test/gc/test-net-timeout.js @@ -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();