Skip to content

Commit

Permalink
test: init logic
Browse files Browse the repository at this point in the history
  • Loading branch information
analog-nico committed Jul 2, 2016
1 parent 88dc127 commit a47762f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/PencilPusher.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class PencilPusher {
if (_.isUndefined(errorMonitoring)) {

this._errorMonitoring = (err) => {
/* istanbul ignore next */
console.error(err)
}

Expand Down
1 change: 1 addition & 0 deletions lib/persistence-layer/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ let persistenceLayerErrors = require('./errors.js')

module.exports = (persistenceLayer, errorMonitoring) => {

/* istanbul ignore if */
if (persistenceLayer.__monitored) {
return
}
Expand Down
46 changes: 46 additions & 0 deletions test/spec/task-errorMonitoring.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,4 +357,50 @@ describe('The error monitoring for task processing', () => {

})

it('should catch errors in the error monitoring itself', (done) => {

let pl = new MemoryPersistenceLayer()
let numCalls = 0
let origFn = pl.getNextPendingTask
pl.getNextPendingTask = (...args) => {
numCalls += 1
if (numCalls === 1) {
throw new Error('Failed!')
}
return Reflect.apply(origFn, pl, args)
}

let pencilPusher = new PencilPusher({
persistenceLayer: pl,
errorMonitoring: (xyz) => {
throw new Error('monitoring failed')
}
})

let stderr = []
let origStderrWrite = process.stderr.write
process.stderr.write = (string, encoding, fd) => {
stderr.push(string)
}

pencilPusher.start()

setTimeout(() => {

try {

process.stderr.write = origStderrWrite

expect(stderr.join('')).to.contain('monitoring failed')

} finally {
pencilPusher.stop()
}

done()

}, DEFAULT_RUNNING_TIME)

})

})

0 comments on commit a47762f

Please sign in to comment.