Skip to content

Commit

Permalink
add option to print errors (#217)
Browse files Browse the repository at this point in the history
* add option to print errors

Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>

* added debug test

Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
  • Loading branch information
yoshuawuyts authored and mcollina committed Nov 1, 2019
1 parent 5a43408 commit 6b2e017
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
5 changes: 3 additions & 2 deletions autocannon.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports.parseArguments = parseArguments

function parseArguments (argvs) {
const argv = minimist(argvs, {
boolean: ['json', 'n', 'help', 'renderLatencyTable', 'renderProgressBar', 'forever', 'idReplacement', 'excludeErrorStats', 'onPort'],
boolean: ['json', 'n', 'help', 'renderLatencyTable', 'renderProgressBar', 'forever', 'idReplacement', 'excludeErrorStats', 'onPort', 'debug'],
alias: {
connections: 'c',
pipelining: 'p',
Expand Down Expand Up @@ -71,7 +71,8 @@ function parseArguments (argvs) {
forever: false,
method: 'GET',
idReplacement: false,
excludeErrorStats: false
excludeErrorStats: false,
debug: false
},
'--': true
})
Expand Down
2 changes: 2 additions & 0 deletions help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ Available options:
Server name for the SNI (Server Name Indication) TLS extension.
-x/--excludeErrorStats
Exclude error statistics (non 2xx http responses) from the final latency and bytes per second averages. default: false.
--debug
Print connection errors to stderr.
-v/--version
Print the version number.
-h/--help
Expand Down
1 change: 1 addition & 0 deletions lib/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ function _run (opts, cb, tracker) {
function onError (error) {
for (let i = 0; i < opts.pipelining; i++) tracker.emit('reqError', error)
errors++
if (opts.debug) console.error(error)
if (opts.bailout && errors >= opts.bailout) stop = true
}

Expand Down
22 changes: 22 additions & 0 deletions test/debug.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict'

const test = require('tap').test
const Autocannon = require('../autocannon')

test('debug works', (t) => {
t.plan(5)

var args = Autocannon.parseArguments([
'-H', 'X-Http-Method-Override=GET',
'-m', 'POST',
'-b', 'the body',
'--debug',
'http://localhost/foo/bar'
])

t.equal(args.url, 'http://localhost/foo/bar')
t.strictSame(args.headers, { 'X-Http-Method-Override': 'GET' })
t.equal(args.method, 'POST')
t.equal(args.body, 'the body')
t.equal(args.debug, true)
})

0 comments on commit 6b2e017

Please sign in to comment.