Updated routes matching

This commit is contained in:
Trial97
2021-08-20 17:33:05 +03:00
committed by Dan Christian Bogos
parent 307337b6bc
commit 806f627b95
3 changed files with 27 additions and 13 deletions

View File

@@ -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))
}
}

View File

@@ -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

View File

@@ -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
}