Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Update tests for http2.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeal authored and ry committed Aug 2, 2011
1 parent a962cca commit 48dcb90
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 76 deletions.
3 changes: 3 additions & 0 deletions test/pummel/test-http-client-reconnect-bug.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
});
Expand Down
18 changes: 14 additions & 4 deletions test/simple/test-http-host-headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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();
});
}
}
50 changes: 29 additions & 21 deletions test/simple/test-http-keep-alive-close-on-header.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
server.listen(common.PORT, function() {
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);
});
35 changes: 12 additions & 23 deletions test/simple/test-http-keep-alive.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
3 changes: 0 additions & 3 deletions test/simple/test-http-many-keep-alive-connections.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ server.listen(common.PORT, function() {
if (++responses < expected) {
callee();
} else {
request.agent.sockets.forEach(function(socket) {
socket.end();
});
server.close();
}
});
Expand Down
23 changes: 11 additions & 12 deletions test/simple/test-http-upgrade-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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');
Expand All @@ -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;
})
});

});
Expand Down
4 changes: 2 additions & 2 deletions test/simple/test-http-upgrade-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {
Expand Down
9 changes: 3 additions & 6 deletions test/simple/test-http-upgrade-client2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -65,7 +64,7 @@ server.listen(common.PORT, function() {
fn && process.nextTick(fn);
}
}
client.on('end', onEnd);
client.on('close', onEnd);

request.write('head');

Expand All @@ -77,8 +76,6 @@ server.listen(common.PORT, function() {
successCount++;
// Test pass
console.log('Pass!');
client.end();
client.destroy();
server.close();
});
});
Expand Down
10 changes: 5 additions & 5 deletions test/simple/test-regress-GH-877.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
}
});
Expand Down

0 comments on commit 48dcb90

Please sign in to comment.