Resilience4j: Why can't waitDurationInHalfOpenState be 0?

Created on 28 May 2019  路  5Comments  路  Source: resilience4j/resilience4j

I am doing some integration tests and I just noticed the exception.
What's the reason behind not allowing the waitDurationInHalfOpenState to be 0?

All 5 comments

why you would do that ?, it is by design default to 60 seconds , meanwhile for more information there is a nice article about circuit breaker in resilience4j by one of the library maintainers :https://dzone.com/articles/circuit-breaker-implementation-in-resilience4j

half open state should be enabled after some waiting time to start testing if the back-end is back to service or not , if u set it to zero , u want to switch from open to half open right away which will not give a chance to your failed back-end to recover from the error state .

I guess you mean waitDurationInOpenState, or?
If you really don't want to wait before switching to half-open, you can set it to 1 millisecond or via code to even 1 nano second.

@RobWin yep, sorry, waitDurationInOpenState. bad copy paste.

@Romeh is just for testing.

I guess my real issue is that I am not finding a way to push time in my spring-boot tests. I am trying to avoid adding sleep calls.

Any recommendation?

You have different options.
1) Inject the CircuitBreakerRegistry in you test, get the CircuitBreaker and do a manual transition to half-open with circuitBreaker.transitionToHalfOpenState()
2) Use a CircuitBreakerRegistry Mock and CircuitBreaker Mock
3) Overwrite system clock

I ended up using circuitBreaker.transitionToHalfOpenState(). Thanks!

Was this page helpful?
0 / 5 - 0 ratings