From 806f627b95712f421944015186fc469df24ae998 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Fri, 20 Aug 2021 17:33:05 +0300 Subject: [PATCH] Updated routes matching --- apier/v1/routes_it_test.go | 19 +++++++++++++++++-- engine/libroutes.go | 8 +------- engine/routes.go | 13 +++++++++---- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/apier/v1/routes_it_test.go b/apier/v1/routes_it_test.go index 962dcccbf..60acebbe6 100644 --- a/apier/v1/routes_it_test.go +++ b/apier/v1/routes_it_test.go @@ -509,7 +509,7 @@ func testV1RouteGetHighestCostRoutes(t *testing.T) { } func testV1RouteGetLeastCostRoutesErr(t *testing.T) { - ev := &engine.ArgsGetRoutes{ + ev := &engine.ArgsGetRoutes{ // it gives error to leastCost but try next because of ignoreErrors flag IgnoreErrors: true, CGREvent: &utils.CGREvent{ Tenant: "cgrates.org", @@ -522,10 +522,25 @@ func testV1RouteGetLeastCostRoutesErr(t *testing.T) { }, }, } + eSpls := engine.SortedRoutesList{{ + ProfileID: "ROUTE_WEIGHT_2", + Sorting: utils.MetaWeight, + Routes: []*engine.SortedRoute{ + { + RouteID: "route1", + SortingData: map[string]interface{}{ + utils.Weight: 10.0, + }, + }, + }, + }} var suplsReply engine.SortedRoutesList if err := routeSv1Rpc.Call(utils.RouteSv1GetRoutes, - ev, &suplsReply); err.Error() != utils.ErrNotFound.Error() { + ev, &suplsReply); err != nil { t.Error(err) + } else if !reflect.DeepEqual(eSpls, suplsReply) { + t.Errorf("Expecting: %s, received: %s", + utils.ToJSON(eSpls), utils.ToJSON(suplsReply)) } } diff --git a/engine/libroutes.go b/engine/libroutes.go index 6f864f094..2400396fe 100644 --- a/engine/libroutes.go +++ b/engine/libroutes.go @@ -245,13 +245,7 @@ func (ssd RouteSortDispatcher) SortRoutes(prflID, strategy string, if !has { return nil, fmt.Errorf("unsupported sorting strategy: %s", strategy) } - if sortedRoutes, err = sd.SortRoutes(prflID, suppls, suplEv, extraOpts); err != nil { - return - } - if len(sortedRoutes.Routes) == 0 { - return nil, utils.ErrNotFound - } - return + return sd.SortRoutes(prflID, suppls, suplEv, extraOpts) } // SortedRoutesList represents the list of matched routes grouped based of profile diff --git a/engine/routes.go b/engine/routes.go index 594a6db4e..f23fd4155 100644 --- a/engine/routes.go +++ b/engine/routes.go @@ -740,12 +740,17 @@ func (rpS *RouteService) sortedRoutesForEvent(tnt string, args *ArgsGetRoutes) ( if sr, err = rpS.sortedRoutesForProfile(tnt, rPrfl, args.CGREvent, prfPag, extraOpts); err != nil { return } - noSrtRoutes += len(sr.Routes) - sortedRoutes = append(sortedRoutes, sr) - if len(sortedRoutes) == prfCount { // the profile count was reached - break + if len(sr.Routes) != 0 { + noSrtRoutes += len(sr.Routes) + sortedRoutes = append(sortedRoutes, sr) + if len(sortedRoutes) == prfCount { // the profile count was reached + break + } } } + if len(sortedRoutes) == 0 { + err = utils.ErrNotFound + } return }