Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
test: migrate pummel/keep-alive to wrk
Browse files Browse the repository at this point in the history
  • Loading branch information
tjfontaine committed Feb 25, 2014
1 parent de56ffa commit d2952cc
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
63 changes: 45 additions & 18 deletions test/pummel/test-keep-alive.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand All @@ -69,15 +98,13 @@ 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');
console.log('normal:' + normalReqSec + ' req/sec');
server.close();
});
});
Expand Down

0 comments on commit d2952cc

Please sign in to comment.