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

hystrix: wrap original err before returning from tryFallback #106

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion hystrix/hystrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func (c *command) tryFallback(ctx context.Context, err error) error {
fallbackErr := c.fallback(ctx, err)
if fallbackErr != nil {
c.reportEvent("fallback-failure")
return fmt.Errorf("fallback failed with '%v'. run error was '%v'", fallbackErr, err)
return fmt.Errorf("fallback failed with '%v'. run error was '%w'", fallbackErr, err)
}

c.reportEvent("fallback-success")
Expand Down
20 changes: 20 additions & 0 deletions hystrix/hystrix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package hystrix

import (
"context"
"errors"
"fmt"
"testing"
"time"
Expand Down Expand Up @@ -215,6 +216,25 @@ func TestFailedFallback(t *testing.T) {
})
}

func TestErrorTypeForTimeoutRunWithFailedFallback(t *testing.T) {
Convey("when your run function times out and fallback functions return an error", t, func() {
defer Flush()
ConfigureCommand("", CommandConfig{Timeout: 100})
errChan := GoC(context.Background(), "", func(ctx context.Context) error {
time.Sleep(200 * time.Millisecond)
return nil
}, func(ctx context.Context, err error) error {
return fmt.Errorf("fallback_error")
})

Convey("the returned error should contain both errors and should be of type ErrTimeout", func() {
err := <-errChan
So(errors.Is(err, ErrTimeout), ShouldBeTrue)
So(err.Error(), ShouldEqual, "fallback failed with 'fallback_error'. run error was 'hystrix: timeout'")
})
})
}

func TestCloseCircuitAfterSuccess(t *testing.T) {
Convey("when a circuit is open", t, func() {
defer Flush()
Expand Down