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

Commit

Permalink
feat(createCircuitBreaker): increase healthcheck interval to 5s (#397)
Browse files Browse the repository at this point in the history
  • Loading branch information
10xLaCroixDrinker authored Dec 17, 2020
1 parent 5e807a7 commit 6f7f222
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions __tests__/server/utils/createCircuitBreaker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('Circuit breaker', () => {
it('should open the circuit when event loop delay threshold is exceeded', async () => {
expect.assertions(2);
setEventLoopDelayThreshold(-1);
jest.advanceTimersByTime(510);
jest.advanceTimersByTime(5e3 + 10);
// Need to fire the breaker once before it will open
await mockCircuitBreaker.fire('hola, mundo');
jest.clearAllMocks();
Expand All @@ -69,7 +69,7 @@ describe('Circuit breaker', () => {
process.env.NODE_ENV = 'development';
expect.assertions(2);
setEventLoopDelayThreshold(-1);
jest.advanceTimersByTime(510);
jest.advanceTimersByTime(5e3 + 10);
// Need to fire the breaker once before it will open
await mockCircuitBreaker.fire('hola, mundo');
jest.clearAllMocks();
Expand All @@ -81,7 +81,7 @@ describe('Circuit breaker', () => {
it('should not open the circuit when threshold not exceeded', async () => {
expect.assertions(2);
setEventLoopDelayThreshold(250);
jest.advanceTimersByTime(510);
jest.advanceTimersByTime(5e3 + 10);
// Need to fire the breaker once before it will open
await mockCircuitBreaker.fire('hola, mundo');
jest.clearAllMocks();
Expand All @@ -94,7 +94,7 @@ describe('Circuit breaker', () => {
expect.assertions(2);
getModule.mockReturnValueOnce(false);
setEventLoopDelayThreshold(-1);
jest.advanceTimersByTime(510);
jest.advanceTimersByTime(5e3 + 10);
// Need to fire the breaker once before it will open
await mockCircuitBreaker.fire('hola, mundo');
jest.clearAllMocks();
Expand All @@ -106,7 +106,7 @@ describe('Circuit breaker', () => {
it('should log when the healthcheck fails', async () => {
expect.assertions(1);
setEventLoopDelayThreshold(-1);
jest.advanceTimersByTime(510);
jest.advanceTimersByTime(5e3 + 10);
await mockCircuitBreaker.fire('hola, mundo');
expect(consoleErrorSpy.mock.calls).toMatchInlineSnapshot(`
Array [
Expand Down
4 changes: 2 additions & 2 deletions src/server/utils/createCircuitBreaker.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ const createCircuitBreaker = (asyncFunctionThatMightFail) => {
const breaker = new CircuitBreaker(asyncFunctionThatMightFail, options);
// Fallback returns true to indicate fallback behavior is needed
breaker.fallback(() => true);
// Check the max event loop delay every 500ms
breaker.healthCheck(checkMaxEventLoopDelay, 500);
// Check the max event loop delay every 5 seconds
breaker.healthCheck(checkMaxEventLoopDelay, 5e3);
// Log when circuit breaker opens and closes
breaker.on('open', () => console.log(`Circuit breaker [${asyncFunctionThatMightFail.name}] opened`));
breaker.on('close', () => console.log(`Circuit breaker [${asyncFunctionThatMightFail.name}] closed`));
Expand Down

0 comments on commit 6f7f222

Please sign in to comment.