Skip to content

Commit

Permalink
fix: HealthCheckError in sync HealthIndicatorFunction
Browse files Browse the repository at this point in the history
Fixes #2083
  • Loading branch information
andreialecu committed Nov 23, 2022
1 parent 07cd184 commit ee06275
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
28 changes: 28 additions & 0 deletions lib/health-check/health-check-executor.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ const unhealthyCheck = async (): Promise<HealthIndicatorResult> => {
});
};

const unhealthyCheckSync = () => {
throw new HealthCheckError('error', {
unhealthy: {
status: 'down',
},
});
};

describe('HealthCheckExecutorService', () => {
let healthCheckExecutor: HealthCheckExecutor;

Expand Down Expand Up @@ -70,6 +78,26 @@ describe('HealthCheckExecutorService', () => {
});
});

it('should return a result object with errors with sync indicator function', async () => {
const result = await healthCheckExecutor.execute([
() => unhealthyCheckSync(),
]);
expect(result).toEqual<HealthCheckResult>({
status: 'error',
info: {},
error: {
unhealthy: {
status: 'down',
},
},
details: {
unhealthy: {
status: 'down',
},
},
});
});

it('should return a result object without errors and with errors', async () => {
const result = await healthCheckExecutor.execute([
() => unhealthyCheck(),
Expand Down
2 changes: 1 addition & 1 deletion lib/health-check/health-check-executor.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class HealthCheckExecutor implements BeforeApplicationShutdown {
const results: HealthIndicatorResult[] = [];
const errors: HealthIndicatorResult[] = [];

const result = await Promise.allSettled(healthIndicators.map((h) => h()));
const result = await Promise.allSettled(healthIndicators.map(async (h) => h()));

result.forEach((res) => {
if (res.status === 'fulfilled') {
Expand Down

0 comments on commit ee06275

Please sign in to comment.