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

fix: handle err with response #81

Merged
merged 4 commits into from
Sep 5, 2023
Merged
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
11 changes: 8 additions & 3 deletions compparallel.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,14 @@ func getValueOrErrorParallel[T any](
ctx, cancel := withCancelAndOptionalTimeout(ctx, r.Timeout)
defer cancel()
value, empty, err := f(ctx, r.Router)
if err != nil &&
!errors.Is(err, routing.ErrNotFound) &&
!r.IgnoreError {
if err != nil {
if r.IgnoreError || errors.Is(err, routing.ErrNotFound) {
log.Debug("getValueOrErrorParallel: not found or ignorable error for router ", r.Router,
" with timeout ", r.Timeout,
" and ignore errors ", r.IgnoreError,
)
return
}
log.Debug("getValueOrErrorParallel: error calling router function for router ", r.Router,
" with timeout ", r.Timeout,
" and ignore errors ", r.IgnoreError,
Expand Down
28 changes: 28 additions & 0 deletions compparallel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,28 @@ func TestComposableParallelFixtures(t *testing.T) {
{key: "/wait/100ms/a", value: "av", searchValCount: 1},
},
},
{
Name: "Return an error even if routers return data alongside the error",
routers: []*ParallelRouter{
{
Timeout: 0,
IgnoreError: true,
Router: &Compose{
PeerRouting: peerRoutingDataWithError{},
},
},
{
Timeout: time.Second,
IgnoreError: true,
Router: &Compose{
PeerRouting: peerRoutingDataWithError{},
},
},
},
FindPeer: []findPeerFixture{
{peerID: "pid1", err: routing.ErrNotFound},
},
},
}

for _, f := range fixtures {
Expand Down Expand Up @@ -402,6 +424,12 @@ func TestComposableParallelFixtures(t *testing.T) {
}
}

type peerRoutingDataWithError struct{}

func (r peerRoutingDataWithError) FindPeer(ctx context.Context, p peer.ID) (peer.AddrInfo, error) {
return peer.AddrInfo{ID: p}, routing.ErrNotFound
}

func newDummyPeerRouting(t testing.TB, ids []peer.ID) routing.PeerRouting {
pr := dummyPeerRouter{}
for _, id := range ids {
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "v0.7.2"
"version": "v0.7.3"
}
Loading