ax(mining): rename cfg to configuration in circuit_breaker_test.go
AX Principle 1 — predictable names over short names. `cfg` requires context to decode; `configuration` is self-describing. Co-Authored-By: Charon <charon@lethean.io>
This commit is contained in:
parent
ae80737a41
commit
caa887325d
1 changed files with 19 additions and 19 deletions
|
|
@ -8,16 +8,16 @@ import (
|
|||
)
|
||||
|
||||
func TestCircuitBreakerDefaultConfig(t *testing.T) {
|
||||
cfg := DefaultCircuitBreakerConfig()
|
||||
configuration := DefaultCircuitBreakerConfig()
|
||||
|
||||
if cfg.FailureThreshold != 3 {
|
||||
t.Errorf("expected FailureThreshold 3, got %d", cfg.FailureThreshold)
|
||||
if configuration.FailureThreshold != 3 {
|
||||
t.Errorf("expected FailureThreshold 3, got %d", configuration.FailureThreshold)
|
||||
}
|
||||
if cfg.ResetTimeout != 30*time.Second {
|
||||
t.Errorf("expected ResetTimeout 30s, got %v", cfg.ResetTimeout)
|
||||
if configuration.ResetTimeout != 30*time.Second {
|
||||
t.Errorf("expected ResetTimeout 30s, got %v", configuration.ResetTimeout)
|
||||
}
|
||||
if cfg.SuccessThreshold != 1 {
|
||||
t.Errorf("expected SuccessThreshold 1, got %d", cfg.SuccessThreshold)
|
||||
if configuration.SuccessThreshold != 1 {
|
||||
t.Errorf("expected SuccessThreshold 1, got %d", configuration.SuccessThreshold)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -63,12 +63,12 @@ func TestCircuitBreakerClosed(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCircuitBreakerOpensAfterFailures(t *testing.T) {
|
||||
cfg := CircuitBreakerConfig{
|
||||
configuration := CircuitBreakerConfig{
|
||||
FailureThreshold: 2,
|
||||
ResetTimeout: time.Minute,
|
||||
SuccessThreshold: 1,
|
||||
}
|
||||
cb := NewCircuitBreaker("test", cfg)
|
||||
cb := NewCircuitBreaker("test", configuration)
|
||||
|
||||
testErr := errors.New("test error")
|
||||
|
||||
|
|
@ -96,12 +96,12 @@ func TestCircuitBreakerOpensAfterFailures(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCircuitBreakerRejectsWhenOpen(t *testing.T) {
|
||||
cfg := CircuitBreakerConfig{
|
||||
configuration := CircuitBreakerConfig{
|
||||
FailureThreshold: 1,
|
||||
ResetTimeout: time.Hour, // Long timeout to keep circuit open
|
||||
SuccessThreshold: 1,
|
||||
}
|
||||
cb := NewCircuitBreaker("test", cfg)
|
||||
cb := NewCircuitBreaker("test", configuration)
|
||||
|
||||
// Open the circuit
|
||||
cb.Execute(func() (interface{}, error) {
|
||||
|
|
@ -128,12 +128,12 @@ func TestCircuitBreakerRejectsWhenOpen(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCircuitBreakerTransitionsToHalfOpen(t *testing.T) {
|
||||
cfg := CircuitBreakerConfig{
|
||||
configuration := CircuitBreakerConfig{
|
||||
FailureThreshold: 1,
|
||||
ResetTimeout: 50 * time.Millisecond,
|
||||
SuccessThreshold: 1,
|
||||
}
|
||||
cb := NewCircuitBreaker("test", cfg)
|
||||
cb := NewCircuitBreaker("test", configuration)
|
||||
|
||||
// Open the circuit
|
||||
cb.Execute(func() (interface{}, error) {
|
||||
|
|
@ -164,12 +164,12 @@ func TestCircuitBreakerTransitionsToHalfOpen(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCircuitBreakerHalfOpenFailureReopens(t *testing.T) {
|
||||
cfg := CircuitBreakerConfig{
|
||||
configuration := CircuitBreakerConfig{
|
||||
FailureThreshold: 1,
|
||||
ResetTimeout: 50 * time.Millisecond,
|
||||
SuccessThreshold: 1,
|
||||
}
|
||||
cb := NewCircuitBreaker("test", cfg)
|
||||
cb := NewCircuitBreaker("test", configuration)
|
||||
|
||||
// Open the circuit
|
||||
cb.Execute(func() (interface{}, error) {
|
||||
|
|
@ -190,12 +190,12 @@ func TestCircuitBreakerHalfOpenFailureReopens(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCircuitBreakerCaching(t *testing.T) {
|
||||
cfg := CircuitBreakerConfig{
|
||||
configuration := CircuitBreakerConfig{
|
||||
FailureThreshold: 1,
|
||||
ResetTimeout: time.Hour,
|
||||
SuccessThreshold: 1,
|
||||
}
|
||||
cb := NewCircuitBreaker("test", cfg)
|
||||
cb := NewCircuitBreaker("test", configuration)
|
||||
|
||||
// Successful call - caches result
|
||||
result, err := cb.Execute(func() (interface{}, error) {
|
||||
|
|
@ -250,12 +250,12 @@ func TestCircuitBreakerGetCached(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCircuitBreakerReset(t *testing.T) {
|
||||
cfg := CircuitBreakerConfig{
|
||||
configuration := CircuitBreakerConfig{
|
||||
FailureThreshold: 1,
|
||||
ResetTimeout: time.Hour,
|
||||
SuccessThreshold: 1,
|
||||
}
|
||||
cb := NewCircuitBreaker("test", cfg)
|
||||
cb := NewCircuitBreaker("test", configuration)
|
||||
|
||||
// Open the circuit
|
||||
cb.Execute(func() (interface{}, error) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue