2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2010-12-04 15:20:34 -08:00
|
|
|
var common = require('../common');
|
|
|
|
var assert = require('assert');
|
2010-12-06 01:33:52 +03:00
|
|
|
// This test requires the program 'ab'
|
2010-12-04 15:20:34 -08:00
|
|
|
var http = require('http');
|
2010-12-06 01:33:52 +03:00
|
|
|
var exec = require('child_process').exec;
|
2010-05-09 15:07:54 -07:00
|
|
|
|
2010-12-04 15:20:34 -08:00
|
|
|
var bodyLength = 12345;
|
2010-05-09 15:07:54 -07:00
|
|
|
|
2016-02-19 11:01:11 +08:00
|
|
|
var body = 'c'.repeat(bodyLength);
|
2010-05-09 15:07:54 -07:00
|
|
|
|
2010-12-06 01:33:52 +03:00
|
|
|
var server = http.createServer(function(req, res) {
|
2010-05-09 15:07:54 -07:00
|
|
|
res.writeHead(200, {
|
2010-12-06 01:33:52 +03:00
|
|
|
'Content-Length': bodyLength,
|
|
|
|
'Content-Type': 'text/plain'
|
2010-05-09 15:07:54 -07:00
|
|
|
});
|
|
|
|
res.end(body);
|
|
|
|
});
|
|
|
|
|
2010-12-04 15:20:34 -08:00
|
|
|
var runs = 0;
|
2010-05-09 15:07:54 -07:00
|
|
|
|
|
|
|
function runAb(opts, callback) {
|
2010-12-06 01:33:52 +03:00
|
|
|
var command = 'ab ' + opts + ' http://127.0.0.1:' + common.PORT + '/';
|
|
|
|
exec(command, function(err, stdout, stderr) {
|
2010-05-09 15:07:54 -07:00
|
|
|
if (err) {
|
2012-06-15 18:58:27 -07:00
|
|
|
if (/ab|apr/mi.test(stderr)) {
|
2015-07-06 03:24:12 +00:00
|
|
|
console.log('1..0 # Skipped: problem spawning `ab`.\n' + stderr);
|
2010-08-13 11:54:40 -04:00
|
|
|
process.reallyExit(0);
|
|
|
|
}
|
2010-05-09 15:07:54 -07:00
|
|
|
process.exit();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var m = /Document Length:\s*(\d+) bytes/mi.exec(stdout);
|
|
|
|
var documentLength = parseInt(m[1]);
|
|
|
|
|
2016-01-30 20:43:11 -08:00
|
|
|
m = /Complete requests:\s*(\d+)/mi.exec(stdout);
|
2010-05-09 15:07:54 -07:00
|
|
|
var completeRequests = parseInt(m[1]);
|
|
|
|
|
2016-01-30 20:43:11 -08:00
|
|
|
m = /HTML transferred:\s*(\d+) bytes/mi.exec(stdout);
|
2010-05-09 15:07:54 -07:00
|
|
|
var htmlTransfered = parseInt(m[1]);
|
|
|
|
|
|
|
|
assert.equal(bodyLength, documentLength);
|
|
|
|
assert.equal(completeRequests * documentLength, htmlTransfered);
|
|
|
|
|
|
|
|
runs++;
|
|
|
|
|
2010-12-06 01:33:52 +03:00
|
|
|
if (callback) callback();
|
2010-05-09 15:07:54 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2010-12-06 01:33:52 +03:00
|
|
|
server.listen(common.PORT, function() {
|
|
|
|
runAb('-c 1 -n 10', function() {
|
|
|
|
console.log('-c 1 -n 10 okay');
|
2010-05-09 15:07:54 -07:00
|
|
|
|
2010-12-06 01:33:52 +03:00
|
|
|
runAb('-c 1 -n 100', function() {
|
|
|
|
console.log('-c 1 -n 100 okay');
|
2010-05-09 15:07:54 -07:00
|
|
|
|
2010-12-06 01:33:52 +03:00
|
|
|
runAb('-c 1 -n 1000', function() {
|
|
|
|
console.log('-c 1 -n 1000 okay');
|
2010-05-09 15:07:54 -07:00
|
|
|
server.close();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2011-10-15 01:08:36 +02:00
|
|
|
process.on('exit', function() {
|
2010-05-09 15:07:54 -07:00
|
|
|
assert.equal(3, runs);
|
|
|
|
});
|