Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make breaker tests run faster #44

Merged
merged 1 commit into from
Jan 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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