From d2952cce36309b33125c749766e70960d20660f5 Mon Sep 17 00:00:00 2001 From: Timothy J Fontaine Date: Mon, 24 Feb 2014 19:40:47 -0800 Subject: [PATCH] test: migrate pummel/keep-alive to wrk --- Makefile | 2 +- test/pummel/test-keep-alive.js | 63 ++++++++++++++++++++++++++++++------------ 2 files changed, 46 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index 231de81..51c6b90 100644 --- a/Makefile +++ b/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 diff --git a/test/pummel/test-keep-alive.js b/test/pummel/test-keep-alive.js index 47ab09d..8611f4d 100644 --- a/test/pummel/test-keep-alive.js +++ b/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,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(); }); }); -- 2.7.4