Update tests for http2.
This commit is contained in:
parent
a962cca390
commit
48dcb905f6
@ -37,11 +37,14 @@ server.on('listening', function() {
|
|||||||
var client = http.createClient(common.PORT);
|
var client = http.createClient(common.PORT);
|
||||||
|
|
||||||
client.addListener('error', function(err) {
|
client.addListener('error', function(err) {
|
||||||
|
// We should receive one error
|
||||||
console.log('ERROR! ' + err.message);
|
console.log('ERROR! ' + err.message);
|
||||||
errorCount++;
|
errorCount++;
|
||||||
});
|
});
|
||||||
|
|
||||||
client.addListener('end', function() {
|
client.addListener('end', function() {
|
||||||
|
// When we remove the old Client interface this will most likely have to be
|
||||||
|
// changed.
|
||||||
console.log('EOF!');
|
console.log('EOF!');
|
||||||
eofCount++;
|
eofCount++;
|
||||||
});
|
});
|
||||||
|
@ -33,9 +33,13 @@ var http = require('http'),
|
|||||||
|
|
||||||
function reqHandler(req, res) {
|
function reqHandler(req, res) {
|
||||||
console.log('Got request: ' + req.headers.host + ' ' + req.url);
|
console.log('Got request: ' + req.headers.host + ' ' + req.url);
|
||||||
assert.equal(req.headers.host, 'localhost:' + common.PORT,
|
if (req.url === '/setHostFalse5') {
|
||||||
'Wrong host header for req[' + req.url + ']: ' +
|
assert.equal(req.headers.host, undefined);
|
||||||
req.headers.host);
|
} else {
|
||||||
|
assert.equal(req.headers.host, 'localhost:' + common.PORT,
|
||||||
|
'Wrong host header for req[' + req.url + ']: ' +
|
||||||
|
req.headers.host);
|
||||||
|
}
|
||||||
res.writeHead(200, {});
|
res.writeHead(200, {});
|
||||||
//process.nextTick(function() { res.end('ok'); });
|
//process.nextTick(function() { res.end('ok'); });
|
||||||
res.end('ok');
|
res.end('ok');
|
||||||
@ -146,5 +150,11 @@ function testHttps() {
|
|||||||
host: 'localhost',
|
host: 'localhost',
|
||||||
//agent: false,
|
//agent: false,
|
||||||
port: common.PORT }, cb).on('error', thrower).end();
|
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();
|
||||||
});
|
});
|
||||||
}
|
}
|
@ -35,34 +35,42 @@ var server = http.createServer(function(req, res) {
|
|||||||
|
|
||||||
var connectCount = 0;
|
var connectCount = 0;
|
||||||
|
|
||||||
|
|
||||||
server.listen(common.PORT, function() {
|
server.listen(common.PORT, function() {
|
||||||
var client = http.createClient(common.PORT);
|
var agent = new http.Agent({maxSockets:1})
|
||||||
|
var request = http.request({method:'GET', path:'/', headers:headers, port:common.PORT, agent:agent}, function () {
|
||||||
client.addListener('connect', function() {
|
assert.equal(1, agent.sockets['localhost:'+common.PORT].length)
|
||||||
common.error('CONNECTED');
|
|
||||||
connectCount++;
|
|
||||||
});
|
});
|
||||||
|
request.on('socket', function (s) {
|
||||||
var request = client.request('GET', '/', headers);
|
s.on('connect', function () {
|
||||||
|
connectCount++;
|
||||||
|
})
|
||||||
|
})
|
||||||
request.end();
|
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() {
|
response.addListener('end', function() {
|
||||||
common.error('response end');
|
assert.equal(1, agent.sockets['localhost:'+common.PORT].length)
|
||||||
var req = client.request('GET', '/', headers);
|
server.close();
|
||||||
req.addListener('response', function(response) {
|
|
||||||
response.addListener('end', function() {
|
|
||||||
client.end();
|
|
||||||
server.close();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
req.end();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
request.on('socket', function (s) {
|
||||||
|
s.on('connect', function () {
|
||||||
|
connectCount++;
|
||||||
|
})
|
||||||
|
})
|
||||||
|
request.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
process.addListener('exit', function() {
|
process.addListener('exit', function() {
|
||||||
assert.equal(2, connectCount);
|
assert.equal(3, connectCount);
|
||||||
});
|
});
|
||||||
|
@ -36,32 +36,21 @@ var server = http.createServer(function(req, res) {
|
|||||||
var connectCount = 0;
|
var connectCount = 0;
|
||||||
|
|
||||||
server.listen(common.PORT, function() {
|
server.listen(common.PORT, function() {
|
||||||
var client = http.createClient(common.PORT);
|
var agent = new http.Agent({maxSockets:1})
|
||||||
|
var request = http.request({method:'GET', path:'/', headers:headers, port:common.PORT, agent:agent}, function () {
|
||||||
client.addListener('connect', function() {
|
assert.equal(1, agent.sockets['localhost:'+common.PORT].length)
|
||||||
common.error('CONNECTED');
|
|
||||||
connectCount++;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var request = client.request('GET', '/', headers);
|
|
||||||
request.end();
|
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() {
|
response.addListener('end', function() {
|
||||||
common.error('response end');
|
assert.equal(1, agent.sockets['localhost:'+common.PORT].length)
|
||||||
var req = client.request('GET', '/', headers);
|
server.close();
|
||||||
req.addListener('response', function(response) {
|
|
||||||
response.addListener('end', function() {
|
|
||||||
client.end();
|
|
||||||
server.close();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
req.end();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
request.end();
|
||||||
|
|
||||||
process.addListener('exit', function() {
|
|
||||||
assert.equal(1, connectCount);
|
|
||||||
});
|
});
|
||||||
|
@ -52,9 +52,6 @@ server.listen(common.PORT, function() {
|
|||||||
if (++responses < expected) {
|
if (++responses < expected) {
|
||||||
callee();
|
callee();
|
||||||
} else {
|
} else {
|
||||||
request.agent.sockets.forEach(function(socket) {
|
|
||||||
socket.end();
|
|
||||||
});
|
|
||||||
server.close();
|
server.close();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -52,12 +52,6 @@ var gotUpgrade = false;
|
|||||||
|
|
||||||
srv.listen(common.PORT, '127.0.0.1', function() {
|
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 = {
|
var options = {
|
||||||
port: common.PORT,
|
port: common.PORT,
|
||||||
host: '127.0.0.1',
|
host: '127.0.0.1',
|
||||||
@ -69,7 +63,7 @@ srv.listen(common.PORT, '127.0.0.1', function() {
|
|||||||
var req = http.request(options);
|
var req = http.request(options);
|
||||||
req.end();
|
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
|
// XXX: This test isn't fantastic, as it assumes that the entire response
|
||||||
// from the server will arrive in a single data callback
|
// from the server will arrive in a single data callback
|
||||||
assert.equal(upgradeHead, 'nurtzo');
|
assert.equal(upgradeHead, 'nurtzo');
|
||||||
@ -79,11 +73,16 @@ srv.listen(common.PORT, '127.0.0.1', function() {
|
|||||||
'connection': 'upgrade',
|
'connection': 'upgrade',
|
||||||
'upgrade': 'websocket' };
|
'upgrade': 'websocket' };
|
||||||
assert.deepEqual(expectedHeaders, res.headers);
|
assert.deepEqual(expectedHeaders, res.headers);
|
||||||
|
assert.equal(http.globalAgent.sockets[options.host+':'+options.port].length, 1);
|
||||||
|
|
||||||
socket.end();
|
process.nextTick(function () {
|
||||||
srv.close();
|
// 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;
|
gotUpgrade = true;
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -52,7 +52,7 @@ var gotUpgrade = false;
|
|||||||
|
|
||||||
srv.listen(common.PORT, '127.0.0.1', function() {
|
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) {
|
hc.addListener('upgrade', function(res, socket, upgradeHead) {
|
||||||
// XXX: This test isn't fantastic, as it assumes that the entire response
|
// XXX: This test isn't fantastic, as it assumes that the entire response
|
||||||
// from the server will arrive in a single data callback
|
// 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;
|
gotUpgrade = true;
|
||||||
});
|
});
|
||||||
hc.request('GET', '/').end();
|
hc.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
process.addListener('exit', function() {
|
process.addListener('exit', function() {
|
||||||
|
@ -39,12 +39,11 @@ var successCount = 0;
|
|||||||
|
|
||||||
server.listen(common.PORT, function() {
|
server.listen(common.PORT, function() {
|
||||||
|
|
||||||
var client = http.createClient(common.PORT);
|
|
||||||
|
|
||||||
function upgradeRequest(fn) {
|
function upgradeRequest(fn) {
|
||||||
console.log("req");
|
console.log("req");
|
||||||
var header = { 'Connection': 'Upgrade', 'Upgrade': 'Test' };
|
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;
|
var wasUpgrade = false;
|
||||||
|
|
||||||
function onUpgrade(res, socket, head) {
|
function onUpgrade(res, socket, head) {
|
||||||
@ -65,7 +64,7 @@ server.listen(common.PORT, function() {
|
|||||||
fn && process.nextTick(fn);
|
fn && process.nextTick(fn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
client.on('end', onEnd);
|
client.on('close', onEnd);
|
||||||
|
|
||||||
request.write('head');
|
request.write('head');
|
||||||
|
|
||||||
@ -77,8 +76,6 @@ server.listen(common.PORT, function() {
|
|||||||
successCount++;
|
successCount++;
|
||||||
// Test pass
|
// Test pass
|
||||||
console.log('Pass!');
|
console.log('Pass!');
|
||||||
client.end();
|
|
||||||
client.destroy();
|
|
||||||
server.close();
|
server.close();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -6,7 +6,7 @@ var N = 20;
|
|||||||
var responses = 0;
|
var responses = 0;
|
||||||
var maxQueued = 0;
|
var maxQueued = 0;
|
||||||
|
|
||||||
var agent = http.getAgent('127.0.0.1', common.PORT);
|
var agent = http.globalAgent;
|
||||||
agent.maxSockets = 10;
|
agent.maxSockets = 10;
|
||||||
|
|
||||||
var server = http.createServer(function (req, res) {
|
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);
|
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 +
|
'/' + 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) {
|
if (maxQueued < (agent.requests['127.0.0.1:'+common.PORT] ? agent.requests['127.0.0.1:'+common.PORT].length : 0)) {
|
||||||
maxQueued = agent.queue.length;
|
maxQueued = (agent.requests['127.0.0.1:'+common.PORT] ? agent.requests['127.0.0.1:'+common.PORT].length : 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user