2010-07-15 20:47:25 +02:00
|
|
|
common = require("../common");
|
|
|
|
assert = common.assert
|
2010-04-14 01:22:12 +02:00
|
|
|
var sys = require("sys"),
|
|
|
|
fs = require("fs"),
|
|
|
|
http = require("http"),
|
|
|
|
url = require("url");
|
|
|
|
|
2010-04-27 05:26:36 +02:00
|
|
|
var chunk = '01234567890123456789';
|
|
|
|
|
2010-04-14 01:22:12 +02:00
|
|
|
// Produce a very large response.
|
|
|
|
var chargen = http.createServer(function (req, res) {
|
2010-04-27 05:26:36 +02:00
|
|
|
var len = parseInt(req.headers['x-len']);
|
|
|
|
assert.ok(len > 0);
|
2010-04-14 01:43:15 +02:00
|
|
|
res.writeHead(200, {"transfer-encoding":"chunked"});
|
|
|
|
for (var i=0; i<len; i++) {
|
2010-04-29 20:57:52 +02:00
|
|
|
if (i % 1000 == 0) print(',');
|
2010-04-14 01:43:15 +02:00
|
|
|
res.write(chunk);
|
|
|
|
}
|
|
|
|
res.end();
|
2010-04-14 01:22:12 +02:00
|
|
|
});
|
|
|
|
chargen.listen(9000);
|
|
|
|
|
|
|
|
// Proxy to the chargen server.
|
|
|
|
var proxy = http.createServer(function (req, res) {
|
2010-04-14 01:43:15 +02:00
|
|
|
var c = http.createClient(9000, 'localhost')
|
2010-04-27 05:26:36 +02:00
|
|
|
|
|
|
|
var len = parseInt(req.headers['x-len']);
|
|
|
|
assert.ok(len > 0);
|
|
|
|
|
|
|
|
var sent = 0;
|
|
|
|
|
|
|
|
|
|
|
|
c.addListener('error', function (e) {
|
2010-06-24 02:40:51 +02:00
|
|
|
console.log('proxy client error. sent ' + sent);
|
2010-04-27 05:26:36 +02:00
|
|
|
throw e;
|
|
|
|
});
|
|
|
|
|
2010-04-14 01:43:15 +02:00
|
|
|
var proxy_req = c.request(req.method, req.url, req.headers);
|
|
|
|
proxy_req.addListener('response', function(proxy_res) {
|
|
|
|
res.writeHead(proxy_res.statusCode, proxy_res.headers);
|
2010-04-27 05:26:36 +02:00
|
|
|
|
2010-04-29 20:57:52 +02:00
|
|
|
var count = 0;
|
|
|
|
|
2010-04-27 05:26:36 +02:00
|
|
|
proxy_res.addListener('data', function(d) {
|
2010-04-29 20:57:52 +02:00
|
|
|
if (count++ % 1000 == 0) print('.');
|
2010-04-27 05:26:36 +02:00
|
|
|
res.write(d);
|
|
|
|
sent += d.length;
|
|
|
|
assert.ok(sent <= (len*chunk.length));
|
2010-04-14 01:43:15 +02:00
|
|
|
});
|
2010-04-27 05:26:36 +02:00
|
|
|
|
2010-04-14 01:43:15 +02:00
|
|
|
proxy_res.addListener('end', function() {
|
2010-04-14 01:22:12 +02:00
|
|
|
res.end();
|
|
|
|
});
|
2010-04-27 05:26:36 +02:00
|
|
|
|
2010-04-14 01:43:15 +02:00
|
|
|
});
|
2010-04-27 05:26:36 +02:00
|
|
|
|
2010-04-14 01:43:15 +02:00
|
|
|
proxy_req.end();
|
2010-04-14 01:22:12 +02:00
|
|
|
});
|
|
|
|
proxy.listen(9001);
|
|
|
|
|
2010-04-14 01:43:15 +02:00
|
|
|
var done = false;
|
2010-04-14 01:22:12 +02:00
|
|
|
|
|
|
|
function call_chargen(list) {
|
|
|
|
if (list.length > 0) {
|
2010-04-27 05:26:36 +02:00
|
|
|
var len = list.shift();
|
|
|
|
|
2010-08-17 12:59:36 +02:00
|
|
|
common.debug("calling chargen for " + len + " chunks.");
|
2010-04-27 05:26:36 +02:00
|
|
|
|
|
|
|
var recved = 0;
|
|
|
|
|
|
|
|
var req = http.createClient(9001, 'localhost').request('/', {'x-len': len});
|
|
|
|
|
2010-04-14 01:22:12 +02:00
|
|
|
req.addListener('response', function(res) {
|
2010-04-27 05:26:36 +02:00
|
|
|
|
|
|
|
res.addListener('data', function(d) {
|
|
|
|
recved += d.length;
|
|
|
|
assert.ok(recved <= (len*chunk.length));
|
|
|
|
});
|
|
|
|
|
2010-04-14 01:22:12 +02:00
|
|
|
res.addListener('end', function() {
|
2010-04-27 05:26:36 +02:00
|
|
|
assert.ok(recved <= (len*chunk.length));
|
2010-08-17 12:59:36 +02:00
|
|
|
common.debug("end for " + len + " chunks.");
|
2010-04-14 01:22:12 +02:00
|
|
|
call_chargen(list);
|
|
|
|
});
|
2010-04-27 05:26:36 +02:00
|
|
|
|
2010-04-14 01:22:12 +02:00
|
|
|
});
|
|
|
|
req.end();
|
2010-04-27 05:26:36 +02:00
|
|
|
|
2010-04-14 01:43:15 +02:00
|
|
|
} else {
|
2010-06-24 02:40:51 +02:00
|
|
|
console.log("End of list. closing servers");
|
2010-04-27 05:26:36 +02:00
|
|
|
proxy.close();
|
|
|
|
chargen.close();
|
|
|
|
done = true;
|
2010-04-14 01:22:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
call_chargen([ 100, 1000, 10000, 100000, 1000000 ]);
|
|
|
|
|
|
|
|
process.addListener('exit', function () {
|
|
|
|
assert.ok(done);
|
|
|
|
});
|