Skip to content

Commit

Permalink
update worker idle memory limit
Browse files Browse the repository at this point in the history
  • Loading branch information
youngbryanyu committed Feb 15, 2024
1 parent 2634936 commit 480cb37
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
3 changes: 2 additions & 1 deletion backend/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ module.exports = {
'!src/config/**', /* exclude config and constants */
'!src/logging/**' /* exclude logging setup */
],
setupFilesAfterEnv: ['./jest.setup.js'] /* Global set up file */
setupFilesAfterEnv: ['./jest.setup.js'] /* Global set up file */,
workerIdleMemoryLimit: '512mb'
};
55 changes: 55 additions & 0 deletions backend/tests/routes/healthCheckRoutes.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* Unit tests for the health check routes */
import request from 'supertest';
import { API_URLS_V1, AUTH_RESPONSES } from '../../src/constants';
import App from '../../src/app';
import Config from 'simple-app-config';
import HealthCheckController from '../../src/controllers/healthCheckController';

/* Mock the controller functions */
jest.mock('../../src/controllers/healthCheckController', () => ({
checkHealth: jest.fn().mockImplementation((req, res) => {
res.sendStatus(200);
})
}));

describe('Health Check Routes Tests', () => {
let appInstance: App;

beforeAll(() => {
appInstance = new App();
});

beforeEach(() => {
jest.restoreAllMocks();
});

describe('GET /healthCheck', () => {
it('should call HealthCheckController.checkHealth', async () => {
/* Make the API call */
const expressInstance = appInstance.getExpressApp();
await request(expressInstance).get(`${API_URLS_V1.HEALTH_CHECK}/healthCheck`).send({});

/* Test against expected */
expect(HealthCheckController.checkHealth).toHaveBeenCalled();
});

it('should fail when the rate limit is exceeded', async () => {
/* Call API `threshold` times so that next call will cause rating limiting */
const expressInstance = appInstance.getExpressApp();
const threshold: number = Config.get('RATE_LIMITING.HEALTH_CHECKS.HEALTH_CHECK.THRESHOLD');
for (let i = 0; i < threshold; i++) {
await request(expressInstance).get(`${API_URLS_V1.HEALTH_CHECK}/healthCheck`).send({});
}

/* Call API */
const response = await request(expressInstance)
.get(`${API_URLS_V1.HEALTH_CHECK}/healthCheck`)
.send({});

/* Test against expected */
expect(HealthCheckController.checkHealth).toHaveBeenCalled();
expect(response.statusCode).toBe(429);
expect(response.body.message).toBe(AUTH_RESPONSES._429_RATE_LIMIT_EXCEEDED);
});
});
});

0 comments on commit 480cb37

Please sign in to comment.