Skip to content

Commit

Permalink
Lazy router: Return error if no route succeeded
Browse files Browse the repository at this point in the history
  • Loading branch information
Krithika Sundararajan committed Nov 4, 2022
1 parent e156b48 commit 0e0fe2c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lazy_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,8 @@ func (r *LazyRouter) Dispatch(ctx context.Context, req Request) ResponseQueue {
}
}
}
} else {
out <- NewErrorResponse(errors.ErrRouterStrategyReturnedEmptyRoutes(req.Protocol())).WithLabels(labels)
}
out <- NewErrorResponse(errors.ErrRouterStrategyReturnedEmptyRoutes(req.Protocol())).WithLabels(labels)
}()

return queue
Expand Down
18 changes: 18 additions & 0 deletions lazy_router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,24 @@ func TestLazyRouter_Dispatch(t *testing.T) {
},
timeout: 100 * time.Millisecond,
},
{
name: "error: no route succeeded",
routes: map[string]fiber.Component{
"route-a": testutils.NewMockComponent(
"route-a",
testUtilsHttp.DelayedResponse{Response: testUtilsHttp.MockResp(500, "A-NOK", nil, fiberErrors.ErrServiceUnavailable(protocol.HTTP))}),
"route-b": testutils.NewMockComponent(
"route-b",
testUtilsHttp.DelayedResponse{Response: testUtilsHttp.MockResp(500, "B-NOK", nil, nil)}),
},
strategy: []string{
"route-a", "route-b",
},
expected: []fiber.Response{
testUtilsHttp.MockResp(501, "", nil, fiberErrors.ErrRouterStrategyReturnedEmptyRoutes(protocol.HTTP)),
},
timeout: 100 * time.Millisecond,
},
{
name: "error: routing strategy succeeded, but route timeout exceeded",
routes: map[string]fiber.Component{
Expand Down

0 comments on commit 0e0fe2c

Please sign in to comment.