Skip to content

Commit

Permalink
test add post review
Browse files Browse the repository at this point in the history
  • Loading branch information
benzekrimaha committed Jul 4, 2024
1 parent ccea8fd commit 1c03a2f
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/unit/CircuitBreaker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { afterEach, beforeEach, describe, expect, test, jest } from '@jest/globa

import { CircuitBreaker, BreakerState } from '../../src/CircuitBreaker';
import { defaultProbeEvaluateInterval } from '../../src/Configuration';
import { PrometheusClient } from '../../src/probes/PrometheusClient';

describe('CircuitBreaker', () => {
let b: CircuitBreaker;
Expand Down Expand Up @@ -135,6 +136,29 @@ describe('CircuitBreaker', () => {
expect(s).toBeCalled();
});

test('should set _failedProbes to true when a probe fails', async () => {
const spy = jest.spyOn(PrometheusClient.prototype, 'instantQuery').mockRejectedValue(new Error('Failed to query Prometheus'));
const config = {
probes: [
{
type: 'prometheusQuery',
prometheus: {
endpoint: 'http://localhost:9090',
timeout: 3000,
},
query: 'up',
threshold: 1,
averagedOverInterval: '1m',
},
],
};
const circuitBreaker = new CircuitBreaker(config);
await circuitBreaker._evaluate();
expect(circuitBreaker._failedProbes).toBe(true);

spy.mockRestore();
});

test('should not schedule next evaluation if not started', async () => {
const config = {
probes: [
Expand Down

0 comments on commit 1c03a2f

Please sign in to comment.