Skip to content

Commit

Permalink
Merge pull request #44 from eapache/faster-breaker-tests
Browse files Browse the repository at this point in the history
Make breaker tests run faster
  • Loading branch information
eapache authored Jan 13, 2024
2 parents b938ac8 + 18dde48 commit 808c606
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions breaker/breaker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ func returnsSuccess() error {
}

func TestBreakerErrorExpiry(t *testing.T) {
breaker := New(2, 1, 1*time.Second)
breaker := New(2, 1, 10*time.Millisecond)

for i := 0; i < 3; i++ {
if err := breaker.Run(returnsError); err != errSomeError {
t.Error(err)
}
time.Sleep(1 * time.Second)
time.Sleep(10 * time.Millisecond)
}

for i := 0; i < 3; i++ {
if err := breaker.Go(returnsError); err != nil {
t.Error(err)
}
time.Sleep(1 * time.Second)
time.Sleep(10 * time.Millisecond)
}
}

Expand Down Expand Up @@ -66,7 +66,7 @@ func TestBreakerPanicsCountAsErrors(t *testing.T) {
}

func TestBreakerStateTransitions(t *testing.T) {
breaker := New(3, 2, 1*time.Second)
breaker := New(3, 2, 10*time.Millisecond)

// three errors opens the breaker
for i := 0; i < 3; i++ {
Expand All @@ -83,7 +83,7 @@ func TestBreakerStateTransitions(t *testing.T) {
}

// wait for it to half-close
time.Sleep(2 * time.Second)
time.Sleep(20 * time.Millisecond)
// one success works, but is not enough to fully close
if err := breaker.Run(returnsSuccess); err != nil {
t.Error(err)
Expand All @@ -98,7 +98,7 @@ func TestBreakerStateTransitions(t *testing.T) {
}

// wait for it to half-close
time.Sleep(2 * time.Second)
time.Sleep(20 * time.Millisecond)
// two successes is enough to close it for good
for i := 0; i < 2; i++ {
if err := breaker.Run(returnsSuccess); err != nil {
Expand All @@ -116,7 +116,7 @@ func TestBreakerStateTransitions(t *testing.T) {
}

func TestBreakerAsyncStateTransitions(t *testing.T) {
breaker := New(3, 2, 1*time.Second)
breaker := New(3, 2, 10*time.Millisecond)

// three errors opens the breaker
for i := 0; i < 3; i++ {
Expand All @@ -136,7 +136,7 @@ func TestBreakerAsyncStateTransitions(t *testing.T) {
}

// wait for it to half-close
time.Sleep(2 * time.Second)
time.Sleep(20 * time.Millisecond)
// one success works, but is not enough to fully close
if err := breaker.Go(returnsSuccess); err != nil {
t.Error(err)
Expand All @@ -153,7 +153,7 @@ func TestBreakerAsyncStateTransitions(t *testing.T) {
}

// wait for it to half-close
time.Sleep(2 * time.Second)
time.Sleep(20 * time.Millisecond)
// two successes is enough to close it for good
for i := 0; i < 2; i++ {
if err := breaker.Go(returnsSuccess); err != nil {
Expand Down

0 comments on commit 808c606

Please sign in to comment.