Skip to content

Commit

Permalink
Improved output of random test
Browse files Browse the repository at this point in the history
When a random test package triggers a unhandled parser exception, the
content of this packet as well as the stack trace are printed in order
to ease debugging
  • Loading branch information
Peter Sorowka committed Jan 15, 2016
1 parent f7efa3b commit 9ba7346
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions testRandom.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@

var mqtt = require('./')
, crypto = require('crypto')
, max = 100000
, i
, start = Date.now() / 1000
, time
, errors = 0

, crypto = require('crypto')
, max = 100000
, i
, start = Date.now() / 1000
, time
, errors = 0
, randomPacket

function doParse () {
var parser = mqtt.parser()
parser.on('error', onError)
parser.parse(crypto.randomBytes(Math.floor(Math.random() * 10)))
randomPacket = crypto.randomBytes(Math.floor(Math.random() * 10))
parser.parse(randomPacket)
}

try {

for (i = 0; i < max; i++) {
doParse()
}
}
catch(e) {

for (i = 0; i < max; i++) {
doParse()
console.log('Exception occured at packet ')
console.log(new Buffer(randomPacket))
console.log(e.message)
console.log(e.stack)
}

function onError () {
Expand Down

0 comments on commit 9ba7346

Please sign in to comment.