2010-12-05 07:20:34 +08:00
|
|
|
var common = require('../common');
|
2010-12-06 06:33:52 +08:00
|
|
|
var assert = require('assert');
|
2009-08-05 17:17:26 +08:00
|
|
|
|
2010-12-06 06:33:52 +08:00
|
|
|
var http = require('http');
|
2010-05-10 04:54:58 +08:00
|
|
|
|
2009-08-05 17:17:26 +08:00
|
|
|
var request_count = 1000;
|
2010-05-10 04:54:58 +08:00
|
|
|
var body = '{"ok": true}';
|
2009-08-05 17:17:26 +08:00
|
|
|
|
2010-05-10 04:54:58 +08:00
|
|
|
var server = http.createServer(function(req, res) {
|
2010-12-06 06:33:52 +08:00
|
|
|
res.writeHead(200, {'Content-Type': 'text/javascript'});
|
|
|
|
res.write(body);
|
|
|
|
res.end();
|
2009-08-05 17:17:26 +08:00
|
|
|
});
|
2010-07-16 02:47:25 +08:00
|
|
|
server.listen(common.PORT);
|
2009-08-05 17:17:26 +08:00
|
|
|
|
|
|
|
var requests_ok = 0;
|
|
|
|
var requests_complete = 0;
|
|
|
|
|
2010-12-06 06:33:52 +08:00
|
|
|
server.addListener('listening', function() {
|
|
|
|
for (var i = 0; i < request_count; i++) {
|
|
|
|
http.cat('http://localhost:' + common.PORT + '/', 'utf8',
|
|
|
|
function(err, content) {
|
|
|
|
requests_complete++;
|
|
|
|
if (err) {
|
|
|
|
common.print('-');
|
|
|
|
} else {
|
|
|
|
assert.equal(body, content);
|
|
|
|
common.print('.');
|
|
|
|
requests_ok++;
|
|
|
|
}
|
|
|
|
if (requests_complete == request_count) {
|
|
|
|
console.log('\nrequests ok: ' + requests_ok);
|
|
|
|
server.close();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2010-05-10 04:54:58 +08:00
|
|
|
});
|
2009-08-05 17:17:26 +08:00
|
|
|
|
2010-12-06 06:33:52 +08:00
|
|
|
process.addListener('exit', function() {
|
2010-05-10 04:54:58 +08:00
|
|
|
assert.equal(request_count, requests_complete);
|
|
|
|
assert.equal(request_count, requests_ok);
|
2009-10-30 06:59:35 +08:00
|
|
|
});
|