Skip to content
This repository has been archived by the owner on Aug 6, 2021. It is now read-only.

Commit

Permalink
Merge pull request #8 from sharelatex/bg-handle-undefined-logger
Browse files Browse the repository at this point in the history
handle undefined logger in event loop monitor
  • Loading branch information
briangough authored May 10, 2018
2 parents 1669619 + 9c1bc55 commit 046d780
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
4 changes: 3 additions & 1 deletion event_loop.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
module.exports = EventLoopMonitor =
monitor: (logger, interval = 1000, log_threshold = 100) ->
Metrics = require "./metrics"

# check for logger on startup to avoid exceptions later if undefined
throw new Error("logger is undefined") if !logger?
# monitor delay in setInterval to detect event loop blocking
previous = Date.now()
intervalId = setInterval () ->
now = Date.now()
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "metrics-sharelatex",
"version": "1.7.1",
"version": "1.7.2",
"description": "A drop-in metrics and monitoring module for node.js apps",
"repository": {
"type": "git",
Expand Down
34 changes: 34 additions & 0 deletions test/unit/coffee/event_loop.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require('coffee-script')
chai = require('chai')
should = chai.should()
expect = chai.expect
path = require('path')
modulePath = path.join __dirname, '../../../event_loop.coffee'
SandboxedModule = require('sandboxed-module')
sinon = require("sinon")

describe 'event_loop', ->

before ->
@metrics = {
timing: sinon.stub()
registerDestructor: sinon.stub()
}
@logger = {
warn: sinon.stub()
}
@event_loop = SandboxedModule.require modulePath, requires:
'./metrics': @metrics

describe 'with a logger provided', ->
before ->
@event_loop.monitor(@logger)

it 'should register a destructor with metrics', ->
@metrics.registerDestructor.called.should.equal true

describe 'without a logger provided', ->

it 'should throw an exception', ->
expect(@event_loop.monitor).to.throw('logger is undefined')

0 comments on commit 046d780

Please sign in to comment.