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();