Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Commit

Permalink
fix(metrics): health check (#274)
Browse files Browse the repository at this point in the history
  • Loading branch information
JAdshead committed Aug 13, 2020
1 parent a59ab8a commit 352bbd3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
12 changes: 5 additions & 7 deletions __tests__/server/middleware/healthCheck.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => ({
Expand Down Expand Up @@ -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,
}));
Expand All @@ -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,
}));
Expand All @@ -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,
}));
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/server/middleware/healthCheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 352bbd3

Please sign in to comment.