cep21 / circuit

An efficient and feature complete Hystrix like Go implementation of the circuit breaker pattern.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Option to mock the clock for Closer.reopenCircuitCheck

gavi-anchorlabs opened this issue · comments

Since we're able to configure the Timekeeper for a Circuit, it would be helpful if the library also allowed mocking the TimeAfterFunc of the reopenCircuitCheck field.

// Closer is hystrix's default half-open logic: try again ever X ms
type Closer struct {
// Tracks when we should try to close an open circuit again
reopenCircuitCheck faststats.TimedCheck
concurrentSuccessfulAttempts faststats.AtomicInt64
closeOnCurrentCount faststats.AtomicInt64
mu sync.Mutex
config ConfigureCloser
}

TimeAfterFunc func(time.Duration, func()) *time.Timer

Great library!

What problem are you trying to solve? With most testing, I test hystrix internally to this library and test users of hystrix/circuit by stubbing out their own closer logic.

If you needed to do this, I believe the right way to do this would be to modify this struct ConfigureCloser with a TimeAfterFunc parameter.

I'd also like this --

my scenario is that under test, I want to provide a very deterministic clock so that I can focus the test on if my understanding of my configuration matches it's reality, that my fallback gets invoked properly, and that i'm generally using the library correctly.

It was very confusing to me that it wasn't there -- I had configured my circuit with a GeneralConfiguration providing a time keeper, and the hystrix.Opener accepts a mock function for Now(). I spent some time trying to figure out why the circuit in my test was not opening (it's SleepWindow exceeded the time it took for the test to execute)

happy to put together an MR