Browse Source

test: migrate pummel/keep-alive to wrk

v0.11.12-release
Timothy J Fontaine 11 years ago
parent
commit
d2952cce36
  1. 2
      Makefile
  2. 59
      test/pummel/test-keep-alive.js

2
Makefile

@ -137,7 +137,7 @@ test-message: test-build
test-simple: all
$(PYTHON) tools/test.py simple
test-pummel: all
test-pummel: all wrk
$(PYTHON) tools/test.py pummel
test-internet: all

59
test/pummel/test-keep-alive.js

@ -20,13 +20,18 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
if (process.platform === 'win32') {
console.log('skipping this test because there is no wrk on windows');
process.exit(0);
}
// This test requires the program 'ab'
// This test requires the program 'wrk'
var common = require('../common');
var assert = require('assert');
var spawn = require('child_process').spawn;
var http = require('http');
var exec = require('child_process').exec;
var path = require('path');
var url = require('url');
var body = 'hello world\n';
var server = http.createServer(function(req, res) {
@ -43,17 +48,41 @@ var normalReqSec = 0;
function runAb(opts, callback) {
var command = 'ab ' + opts + ' http://127.0.0.1:' + common.PORT + '/';
exec(command, function(err, stdout, stderr) {
if (err) {
if (stderr.indexOf('ab') >= 0) {
console.log('ab not installed? skipping test.\n' + stderr);
process.reallyExit(0);
var args = [
'-c', opts.concurrent || 100,
'-t', opts.threads || 2,
'-d', opts.duration || '10s',
];
if (!opts.keepalive) {
args.push('-H');
args.push('Connection: close');
}
args.push(url.format({ hostname: '127.0.0.1', port: common.PORT, protocol: 'http'}));
var comm = path.join(__dirname, '..', '..', 'tools', 'wrk', 'wrk');
//console.log(comm, args.join(' '));
var child = spawn(comm, args);
child.stderr.pipe(process.stderr);
child.stdout.setEncoding('utf8');
var stdout;
child.stdout.on('data', function(data) {
stdout += data;
});
child.on('close', function(code, signal) {
if (code) {
console.error(code, signal);
process.exit(code);
return;
}
if (err) throw err;
var matches = /Requests per second:\s*(\d+)\./mi.exec(stdout);
var matches = /Requests\/sec:\s*(\d+)\./mi.exec(stdout);
var reqSec = parseInt(matches[1]);
matches = /Keep-Alive requests:\s*(\d+)/mi.exec(stdout);
@ -69,14 +98,12 @@ function runAb(opts, callback) {
}
server.listen(common.PORT, function() {
runAb('-k -c 100 -t 2', function(reqSec, keepAliveRequests) {
runAb({ keepalive: true }, function(reqSec) {
keepAliveReqSec = reqSec;
assert.equal(true, keepAliveRequests > 0);
console.log('keep-alive: ' + keepAliveReqSec + ' req/sec');
console.log('keep-alive:', keepAliveReqSec, 'req/sec');
runAb('-c 100 -t 2', function(reqSec, keepAliveRequests) {
runAb({ keepalive: false }, function(reqSec) {
normalReqSec = reqSec;
assert.equal(0, keepAliveRequests);
console.log('normal:' + normalReqSec + ' req/sec');
server.close();
});

Loading…
Cancel
Save