mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Merge pull request #8 from sharelatex/bg-handle-undefined-logger
handle undefined logger in event loop monitor
This commit is contained in:
commit
f1a1002167
3 changed files with 38 additions and 2 deletions
|
@ -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()
|
||||
|
|
|
@ -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",
|
||||
|
|
34
libraries/metrics/test/unit/coffee/event_loop.coffee
Normal file
34
libraries/metrics/test/unit/coffee/event_loop.coffee
Normal file
|
@ -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')
|
||||
|
Loading…
Reference in a new issue