Skip to content

Commit

Permalink
added more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zotya committed Sep 27, 2023
1 parent a46e825 commit 236e4f2
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/config/healthcheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export async function getStatus(appConfig, params) {
resolve(status);
});
}
export default async function healthcheck(appConfig, query) {
export default async function healthcheck(appConfig, params) {
// is index ok?
// return index update date
// run default query, see number of results
Expand All @@ -244,7 +244,8 @@ export default async function healthcheck(appConfig, query) {
queryTimeSecondsThreshold_WARNING,
failedSyncThreshold_OK,
failedSyncThreshold_WARNING,
} = query;
now,
} = params;
documentCountThreshold =
documentCountThreshold || default_documentCountThreshold;
queryTimeSecondsThreshold_OK =
Expand All @@ -260,6 +261,7 @@ export default async function healthcheck(appConfig, query) {
const airflow_params = {
FAILED_SYNC_THRESHOLD_WARNING: failedSyncThreshold_WARNING,
FAILED_SYNC_THRESHOLD_OK: failedSyncThreshold_OK,
now: now,
};

///////////////////
Expand Down
48 changes: 46 additions & 2 deletions src/config/healthcheck.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
getlastsuccessfultasks_for_site,
getStatus,
} from './healthcheck';
import healthcheck from './healthcheck';

import { runRequest } from '@eeacms/search';

import failed_scheduled_atempts_since_last_started_resp from './healthcheck_queries/failed_scheduled_atempts_since_last_started_resp.json';
Expand All @@ -24,6 +26,7 @@ const SLOTS = [
jest.mock('@eeacms/search', () => ({
SLOTS: SLOTS,
runRequest: jest.fn(),
buildRequest: jest.fn(),
}));

const query1 = {
Expand Down Expand Up @@ -231,6 +234,47 @@ describe('test parsing the response from elasticsearch for empty response', () =
describe('test the status of the index', () => {
it('test', async () => {
runRequest
.mockReturnValueOnce(
Promise.resolve({ body: last_scheduled_started_indexing_resp }),
)
.mockReturnValueOnce(
Promise.resolve({
body: failed_scheduled_atempts_since_last_started_resp,
}),
)
.mockReturnValueOnce(
Promise.resolve({
body: last_sync_task_since_last_start_resp,
}),
// )
// .mockReturnValueOnce(
// Promise.resolve({
// body: started_or_finished_site_since_last_started_resp,
// }),
);
const params = { index_name: 'test_index', now: 1695732000000 };
const status = await getStatus({}, params);
expect(status).toEqual({ status: 'OK' });
});
});

describe('test the healthcheck', () => {
it('test', async () => {
runRequest
.mockReturnValueOnce(
Promise.resolve({ body: { hits: { total: { value: 60001 } } } }),
)
.mockReturnValueOnce(
Promise.resolve({
body: {
elapsed: {
step1: [{ query: { delta: 0.5 } }],
step2: [{ query: { delta: 0.6 } }],
},
},
}),
)

.mockReturnValueOnce(
Promise.resolve({ body: last_scheduled_started_indexing_resp }),
)
Expand All @@ -250,7 +294,7 @@ describe('test the status of the index', () => {
}),
);
const params = { index_name: 'test_index', now: 1695732000000 };
const status = await getStatus({}, params);
expect(status).toEqual({ status: 'OK' });
const status = await healthcheck({}, params);
expect(status).toEqual({ status: '1K' });
});
});

0 comments on commit 236e4f2

Please sign in to comment.