From a869609eae0f5e2913aefecb7808f4444f982bd2 Mon Sep 17 00:00:00 2001 From: Jonathan Adshead Date: Tue, 11 Aug 2020 14:20:36 -0700 Subject: [PATCH] fix(metrics): health check --- __tests__/server/middleware/healthCheck.spec.js | 12 +++++------- src/server/middleware/healthCheck.js | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/__tests__/server/middleware/healthCheck.spec.js b/__tests__/server/middleware/healthCheck.spec.js index 8b8c1f8f0..c73a759eb 100644 --- a/__tests__/server/middleware/healthCheck.spec.js +++ b/__tests__/server/middleware/healthCheck.spec.js @@ -28,9 +28,7 @@ jest.mock('holocron', () => ({ getModule: jest.fn(), })); -jest.mock('pidusage', () => ({ - stat: jest.fn(), -})); +jest.mock('pidusage', () => jest.fn()); jest.mock('../../../src/server/utils/stateConfig', () => ({ getClientStateConfig: jest.fn(() => ({ @@ -150,7 +148,7 @@ describe('healthCheck', () => { describe('middleware', () => { it('should return a 200 when all is good', async () => { - pidusage.stat.mockImplementationOnce((pid, cb) => cb(undefined, { + pidusage.mockImplementationOnce((pid, cb) => cb(undefined, { cpu: 80, memory: 1.4e9, })); @@ -165,7 +163,7 @@ describe('healthCheck', () => { }); it('should return a 207 when the module map is not healthy', async () => { - pidusage.stat.mockImplementationOnce((pid, cb) => cb(undefined, { + pidusage.mockImplementationOnce((pid, cb) => cb(undefined, { cpu: 80, memory: 1.4e9, })); @@ -180,7 +178,7 @@ describe('healthCheck', () => { }); it('should return a 503 when any threshold has been passed', async () => { - pidusage.stat.mockImplementationOnce((pid, cb) => cb(undefined, { + pidusage.mockImplementationOnce((pid, cb) => cb(undefined, { cpu: 80.1, memory: 1.4e9, })); @@ -195,7 +193,7 @@ describe('healthCheck', () => { }); it('should return a 500 if it can\'t get the stats', async () => { - pidusage.stat.mockImplementationOnce((pid, cb) => cb(new Error('no stats'))); + pidusage.mockImplementationOnce((pid, cb) => cb(new Error('no stats'))); getModule.mockReturnValueOnce(() => 0); getModuleMapHealth.mockReturnValueOnce(true); await healthCheck(req, res); diff --git a/src/server/middleware/healthCheck.js b/src/server/middleware/healthCheck.js index 76dd79d17..f8333a794 100644 --- a/src/server/middleware/healthCheck.js +++ b/src/server/middleware/healthCheck.js @@ -20,7 +20,7 @@ import { getModule } from 'holocron'; import { getClientStateConfig } from '../utils/stateConfig'; import { getModuleMapHealth } from '../utils/pollModuleMap'; -const getProcessStats = (pid) => promisify((cb) => pidusage.stat(pid, cb))(); +const getProcessStats = (pid) => promisify((cb) => pidusage(pid, cb))(); export const getTickDelay = () => new Promise((resolve) => { const time = process.hrtime();