diff --git a/test/pummel/test-http-client-reconnect-bug.js b/test/pummel/test-http-client-reconnect-bug.js index ada1c22035a..e26fe09e219 100644 --- a/test/pummel/test-http-client-reconnect-bug.js +++ b/test/pummel/test-http-client-reconnect-bug.js @@ -37,11 +37,14 @@ server.on('listening', function() { var client = http.createClient(common.PORT); client.addListener('error', function(err) { + // We should receive one error console.log('ERROR! ' + err.message); errorCount++; }); client.addListener('end', function() { + // When we remove the old Client interface this will most likely have to be + // changed. console.log('EOF!'); eofCount++; }); diff --git a/test/simple/test-http-host-headers.js b/test/simple/test-http-host-headers.js index 7db175a4d09..25ef56ea303 100644 --- a/test/simple/test-http-host-headers.js +++ b/test/simple/test-http-host-headers.js @@ -33,9 +33,13 @@ var http = require('http'), function reqHandler(req, res) { console.log('Got request: ' + req.headers.host + ' ' + req.url); - assert.equal(req.headers.host, 'localhost:' + common.PORT, - 'Wrong host header for req[' + req.url + ']: ' + - req.headers.host); + if (req.url === '/setHostFalse5') { + assert.equal(req.headers.host, undefined); + } else { + assert.equal(req.headers.host, 'localhost:' + common.PORT, + 'Wrong host header for req[' + req.url + ']: ' + + req.headers.host); + } res.writeHead(200, {}); //process.nextTick(function() { res.end('ok'); }); res.end('ok'); @@ -146,5 +150,11 @@ function testHttps() { host: 'localhost', //agent: false, port: common.PORT }, cb).on('error', thrower).end(); + + https.get({ method: 'GET', + path: '/setHostFalse' + (counter++), + host: 'localhost', + setHost: false, + port: common.PORT }, cb).on('error', thrower).end(); }); -} +} \ No newline at end of file diff --git a/test/simple/test-http-keep-alive-close-on-header.js b/test/simple/test-http-keep-alive-close-on-header.js index 506f207f834..741f4a517f8 100644 --- a/test/simple/test-http-keep-alive-close-on-header.js +++ b/test/simple/test-http-keep-alive-close-on-header.js @@ -35,34 +35,42 @@ var server = http.createServer(function(req, res) { var connectCount = 0; + server.listen(common.PORT, function() { - var client = http.createClient(common.PORT); - - client.addListener('connect', function() { - common.error('CONNECTED'); - connectCount++; + var agent = new http.Agent({maxSockets:1}) + var request = http.request({method:'GET', path:'/', headers:headers, port:common.PORT, agent:agent}, function () { + assert.equal(1, agent.sockets['localhost:'+common.PORT].length) }); - - var request = client.request('GET', '/', headers); + request.on('socket', function (s) { + s.on('connect', function () { + connectCount++; + }) + }) request.end(); - request.addListener('response', function(response) { - common.error('response start'); - - + + request = http.request({method:'GET', path:'/', headers:headers, port:common.PORT, agent:agent}, function () { + assert.equal(1, agent.sockets['localhost:'+common.PORT].length) + }); + request.on('socket', function (s) { + s.on('connect', function () { + connectCount++; + }) + }) + request.end(); + request = http.request({method:'GET', path:'/', headers:headers, port:common.PORT, agent:agent}, function(response) { response.addListener('end', function() { - common.error('response end'); - var req = client.request('GET', '/', headers); - req.addListener('response', function(response) { - response.addListener('end', function() { - client.end(); - server.close(); - }); - }); - req.end(); + assert.equal(1, agent.sockets['localhost:'+common.PORT].length) + server.close(); }); }); + request.on('socket', function (s) { + s.on('connect', function () { + connectCount++; + }) + }) + request.end(); }); process.addListener('exit', function() { - assert.equal(2, connectCount); + assert.equal(3, connectCount); }); diff --git a/test/simple/test-http-keep-alive.js b/test/simple/test-http-keep-alive.js index ca67fccdb02..1c5119acfeb 100644 --- a/test/simple/test-http-keep-alive.js +++ b/test/simple/test-http-keep-alive.js @@ -36,32 +36,21 @@ var server = http.createServer(function(req, res) { var connectCount = 0; server.listen(common.PORT, function() { - var client = http.createClient(common.PORT); - - client.addListener('connect', function() { - common.error('CONNECTED'); - connectCount++; + var agent = new http.Agent({maxSockets:1}) + var request = http.request({method:'GET', path:'/', headers:headers, port:common.PORT, agent:agent}, function () { + assert.equal(1, agent.sockets['localhost:'+common.PORT].length) }); - - var request = client.request('GET', '/', headers); request.end(); - request.addListener('response', function(response) { - common.error('response start'); - + + request = http.request({method:'GET', path:'/', headers:headers, port:common.PORT, agent:agent}, function () { + assert.equal(1, agent.sockets['localhost:'+common.PORT].length) + }); + request.end(); + request = http.request({method:'GET', path:'/', headers:headers, port:common.PORT, agent:agent}, function(response) { response.addListener('end', function() { - common.error('response end'); - var req = client.request('GET', '/', headers); - req.addListener('response', function(response) { - response.addListener('end', function() { - client.end(); - server.close(); - }); - }); - req.end(); + assert.equal(1, agent.sockets['localhost:'+common.PORT].length) + server.close(); }); }); -}); - -process.addListener('exit', function() { - assert.equal(1, connectCount); + request.end(); }); diff --git a/test/simple/test-http-many-keep-alive-connections.js b/test/simple/test-http-many-keep-alive-connections.js index a16987081c9..127ff6d5a3d 100644 --- a/test/simple/test-http-many-keep-alive-connections.js +++ b/test/simple/test-http-many-keep-alive-connections.js @@ -52,9 +52,6 @@ server.listen(common.PORT, function() { if (++responses < expected) { callee(); } else { - request.agent.sockets.forEach(function(socket) { - socket.end(); - }); server.close(); } }); diff --git a/test/simple/test-http-upgrade-agent.js b/test/simple/test-http-upgrade-agent.js index 9f80590309f..ec83ddffaad 100644 --- a/test/simple/test-http-upgrade-agent.js +++ b/test/simple/test-http-upgrade-agent.js @@ -52,12 +52,6 @@ var gotUpgrade = false; srv.listen(common.PORT, '127.0.0.1', function() { - var agent = http.getAgent({ - host: '127.0.0.1', - port: common.PORT - }); - assert.ok(agent); - var options = { port: common.PORT, host: '127.0.0.1', @@ -69,7 +63,7 @@ srv.listen(common.PORT, '127.0.0.1', function() { var req = http.request(options); req.end(); - agent.on('upgrade', function(res, socket, upgradeHead) { + req.on('upgrade', function(res, socket, upgradeHead) { // XXX: This test isn't fantastic, as it assumes that the entire response // from the server will arrive in a single data callback assert.equal(upgradeHead, 'nurtzo'); @@ -79,11 +73,16 @@ srv.listen(common.PORT, '127.0.0.1', function() { 'connection': 'upgrade', 'upgrade': 'websocket' }; assert.deepEqual(expectedHeaders, res.headers); - - socket.end(); - srv.close(); - - gotUpgrade = true; + assert.equal(http.globalAgent.sockets[options.host+':'+options.port].length, 1); + + process.nextTick(function () { + // Make sure this request got removed from the pool. + assert.equal(http.globalAgent.sockets[options.host+':'+options.port].length, 0); + socket.end(); + srv.close(); + + gotUpgrade = true; + }) }); }); diff --git a/test/simple/test-http-upgrade-client.js b/test/simple/test-http-upgrade-client.js index 541e86b60cf..0bfeabb83a3 100644 --- a/test/simple/test-http-upgrade-client.js +++ b/test/simple/test-http-upgrade-client.js @@ -52,7 +52,7 @@ var gotUpgrade = false; srv.listen(common.PORT, '127.0.0.1', function() { - var hc = http.createClient(common.PORT, '127.0.0.1'); + var hc = http.createClient(common.PORT, '127.0.0.1').request('GET', '/'); hc.addListener('upgrade', function(res, socket, upgradeHead) { // XXX: This test isn't fantastic, as it assumes that the entire response // from the server will arrive in a single data callback @@ -69,7 +69,7 @@ srv.listen(common.PORT, '127.0.0.1', function() { gotUpgrade = true; }); - hc.request('GET', '/').end(); + hc.end(); }); process.addListener('exit', function() { diff --git a/test/simple/test-http-upgrade-client2.js b/test/simple/test-http-upgrade-client2.js index 147a1bd74cd..6f0d4110abc 100644 --- a/test/simple/test-http-upgrade-client2.js +++ b/test/simple/test-http-upgrade-client2.js @@ -39,12 +39,11 @@ var successCount = 0; server.listen(common.PORT, function() { - var client = http.createClient(common.PORT); - function upgradeRequest(fn) { console.log("req"); var header = { 'Connection': 'Upgrade', 'Upgrade': 'Test' }; - var request = client.request('GET', '/', header); + var request = http.createClient(common.PORT).request('GET', '/', header); + var client = request; var wasUpgrade = false; function onUpgrade(res, socket, head) { @@ -65,7 +64,7 @@ server.listen(common.PORT, function() { fn && process.nextTick(fn); } } - client.on('end', onEnd); + client.on('close', onEnd); request.write('head'); @@ -77,8 +76,6 @@ server.listen(common.PORT, function() { successCount++; // Test pass console.log('Pass!'); - client.end(); - client.destroy(); server.close(); }); }); diff --git a/test/simple/test-regress-GH-877.js b/test/simple/test-regress-GH-877.js index 63af368caa2..d7fc8fc3a4e 100644 --- a/test/simple/test-regress-GH-877.js +++ b/test/simple/test-regress-GH-877.js @@ -6,7 +6,7 @@ var N = 20; var responses = 0; var maxQueued = 0; -var agent = http.getAgent('127.0.0.1', common.PORT); +var agent = http.globalAgent; agent.maxSockets = 10; var server = http.createServer(function (req, res) { @@ -29,12 +29,12 @@ server.listen(common.PORT, "127.0.0.1", function() { assert.equal(req.agent, agent); - console.log('Socket: ' + agent.sockets.length + + console.log('Socket: ' + agent.sockets['127.0.0.1:'+common.PORT].length + '/' + agent.maxSockets + - ' queued: '+ agent.queue.length); + ' queued: '+ (agent.requests['127.0.0.1:'+common.PORT] ? agent.requests['127.0.0.1:'+common.PORT].length : 0)); - if (maxQueued < agent.queue.length) { - maxQueued = agent.queue.length; + if (maxQueued < (agent.requests['127.0.0.1:'+common.PORT] ? agent.requests['127.0.0.1:'+common.PORT].length : 0)) { + maxQueued = (agent.requests['127.0.0.1:'+common.PORT] ? agent.requests['127.0.0.1:'+common.PORT].length : 0); } } });