Browse Source

Update tests for http2.

v0.7.4-release
Mikeal Rogers 13 years ago
committed by Ryan Dahl
parent
commit
48dcb905f6
  1. 3
      test/pummel/test-http-client-reconnect-bug.js
  2. 18
      test/simple/test-http-host-headers.js
  3. 50
      test/simple/test-http-keep-alive-close-on-header.js
  4. 35
      test/simple/test-http-keep-alive.js
  5. 3
      test/simple/test-http-many-keep-alive-connections.js
  6. 23
      test/simple/test-http-upgrade-agent.js
  7. 4
      test/simple/test-http-upgrade-client.js
  8. 9
      test/simple/test-http-upgrade-client2.js
  9. 10
      test/simple/test-regress-GH-877.js

3
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++;
});

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

50
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++;
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
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();
});

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

23
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;
})
});
});

4
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() {

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

10
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);
}
}
});

Loading…
Cancel
Save