Skip to content

Commit

Permalink
Pr53 with unit tests (#54)
Browse files Browse the repository at this point in the history
* SetConfigThreadSafe should set notThreadSafeConfig to new config first

Change-Id: Ib8cde17faa1054e511d64ad23199ef519dc7e307

* Add unit test for setting circuit config

* Expand config unit test

Check the before and after state to make sure it changed
  • Loading branch information
cep21 authored Oct 16, 2018
1 parent ba9ebf1 commit 14b9f8e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
3 changes: 1 addition & 2 deletions circuit.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,8 @@ func (c *Circuit) ConcurrentFallbacks() int64 {
func (c *Circuit) SetConfigThreadSafe(config Config) {
c.notThreadSafeConfigMu.Lock()
defer c.notThreadSafeConfigMu.Unlock()
//c.circuitStats.SetConfigThreadSafe(config)
c.threadSafeConfig.reset(c.notThreadSafeConfig)
c.notThreadSafeConfig = config
c.threadSafeConfig.reset(c.notThreadSafeConfig)
if cfg, ok := c.OpenToClose.(Configurable); ok {
cfg.SetConfigThreadSafe(config)
}
Expand Down
16 changes: 16 additions & 0 deletions circuit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,22 @@ func TestFailingFallbackCircuit(t *testing.T) {
}
}

func TestSetConfigThreadSafe(t *testing.T) {
var breaker Circuit

if breaker.threadSafeConfig.CircuitBreaker.Disabled.Get() {
t.Error("Circuit should start off not disabled")
}
breaker.SetConfigThreadSafe(Config{
General: GeneralConfig{
Disabled: true,
},
})
if !breaker.threadSafeConfig.CircuitBreaker.Disabled.Get() {
t.Error("Circuit should be disabled after setting config to disabled")
}
}

//func TestSLO(t *testing.T) {
// c := NewCircuitFromConfig("TestFailingCircuit", Config{
// GoSpecific: GoSpecificConfig{
Expand Down

0 comments on commit 14b9f8e

Please sign in to comment.