Add more asserts to test-http-big-proxy-responses
This commit is contained in:
parent
c6248efd73
commit
c7b3c1ecbc
@ -4,13 +4,15 @@ fs = require("fs"),
|
|||||||
http = require("http"),
|
http = require("http"),
|
||||||
url = require("url");
|
url = require("url");
|
||||||
|
|
||||||
|
var chunk = '01234567890123456789';
|
||||||
|
|
||||||
// Produce a very large response.
|
// Produce a very large response.
|
||||||
var chargen = http.createServer(function (req, res) {
|
var chargen = http.createServer(function (req, res) {
|
||||||
var chunk = '01234567890123456789';
|
var len = parseInt(req.headers['x-len']);
|
||||||
var len = req.headers['x-len'];
|
assert.ok(len > 0);
|
||||||
res.writeHead(200, {"transfer-encoding":"chunked"});
|
res.writeHead(200, {"transfer-encoding":"chunked"});
|
||||||
for (var i=0; i<len; i++) {
|
for (var i=0; i<len; i++) {
|
||||||
print(',');
|
//print(',');
|
||||||
res.write(chunk);
|
res.write(chunk);
|
||||||
}
|
}
|
||||||
res.end();
|
res.end();
|
||||||
@ -20,17 +22,35 @@ chargen.listen(9000);
|
|||||||
// Proxy to the chargen server.
|
// Proxy to the chargen server.
|
||||||
var proxy = http.createServer(function (req, res) {
|
var proxy = http.createServer(function (req, res) {
|
||||||
var c = http.createClient(9000, 'localhost')
|
var c = http.createClient(9000, 'localhost')
|
||||||
|
|
||||||
|
var len = parseInt(req.headers['x-len']);
|
||||||
|
assert.ok(len > 0);
|
||||||
|
|
||||||
|
var sent = 0;
|
||||||
|
|
||||||
|
|
||||||
|
c.addListener('error', function (e) {
|
||||||
|
puts('proxy client error. sent ' + sent);
|
||||||
|
throw e;
|
||||||
|
});
|
||||||
|
|
||||||
var proxy_req = c.request(req.method, req.url, req.headers);
|
var proxy_req = c.request(req.method, req.url, req.headers);
|
||||||
proxy_req.addListener('response', function(proxy_res) {
|
proxy_req.addListener('response', function(proxy_res) {
|
||||||
res.writeHead(proxy_res.statusCode, proxy_res.headers);
|
res.writeHead(proxy_res.statusCode, proxy_res.headers);
|
||||||
proxy_res.addListener('data', function(chunk) {
|
|
||||||
print('.');
|
proxy_res.addListener('data', function(d) {
|
||||||
res.write(chunk);
|
//print('.');
|
||||||
|
res.write(d);
|
||||||
|
sent += d.length;
|
||||||
|
assert.ok(sent <= (len*chunk.length));
|
||||||
});
|
});
|
||||||
|
|
||||||
proxy_res.addListener('end', function() {
|
proxy_res.addListener('end', function() {
|
||||||
res.end();
|
res.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
proxy_req.end();
|
proxy_req.end();
|
||||||
});
|
});
|
||||||
proxy.listen(9001);
|
proxy.listen(9001);
|
||||||
@ -39,20 +59,34 @@ var done = false;
|
|||||||
|
|
||||||
function call_chargen(list) {
|
function call_chargen(list) {
|
||||||
if (list.length > 0) {
|
if (list.length > 0) {
|
||||||
sys.debug("calling chargen for " + list[0] + " chunks.");
|
var len = list.shift();
|
||||||
var req = http.createClient(9001, 'localhost').request('/', {'x-len': list[0]});
|
|
||||||
|
sys.debug("calling chargen for " + len + " chunks.");
|
||||||
|
|
||||||
|
var recved = 0;
|
||||||
|
|
||||||
|
var req = http.createClient(9001, 'localhost').request('/', {'x-len': len});
|
||||||
|
|
||||||
req.addListener('response', function(res) {
|
req.addListener('response', function(res) {
|
||||||
|
|
||||||
|
res.addListener('data', function(d) {
|
||||||
|
recved += d.length;
|
||||||
|
assert.ok(recved <= (len*chunk.length));
|
||||||
|
});
|
||||||
|
|
||||||
res.addListener('end', function() {
|
res.addListener('end', function() {
|
||||||
sys.debug("end for " + list[0] + " chunks.");
|
assert.ok(recved <= (len*chunk.length));
|
||||||
list.shift();
|
sys.debug("end for " + len + " chunks.");
|
||||||
call_chargen(list);
|
call_chargen(list);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
req.end();
|
req.end();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
sys.puts("End of list.");
|
sys.puts("End of list. closing servers");
|
||||||
proxy.end();
|
proxy.close();
|
||||||
chargen.end();
|
chargen.close();
|
||||||
done = true;
|
done = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user