In case we have UnauthorizedDestination error in GetRatingPlansCost we go to next RatingPlan

This commit is contained in:
TeoV
2019-07-29 16:45:55 +03:00
committed by Dan Christian Bogos
parent e66b9177b3
commit 5d7db1db47
2 changed files with 69 additions and 1 deletions

View File

@@ -28,6 +28,7 @@ import (
"time"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/dispatchers"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
@@ -48,6 +49,10 @@ var sTestsAPIer = []func(t *testing.T){
testAPIerLoadFromFolder,
testAPIerDeleteTPFromFolder,
testAPIerAfterDelete,
testAPIerLoadFromFolder,
testAPIerGetRatingPlanCost,
testAPIerGetRatingPlanCost2,
testAPIerGetRatingPlanCost3,
testAPIerKillEngine,
}
@@ -132,6 +137,66 @@ func testAPIerAfterDelete(t *testing.T) {
}
}
func testAPIerGetRatingPlanCost(t *testing.T) {
arg := &utils.RatingPlanCostArg{
Destination: "1002",
RatingPlanIDs: []string{"RP_1001", "RP_1002"},
SetupTime: utils.META_NOW,
Usage: "1h",
}
var reply dispatchers.RatingPlanCost
if err := apierRPC.Call(utils.RALsV1GetRatingPlansCost, arg, &reply); err != nil {
t.Error(err)
} else if reply.RatingPlanID != "RP_1001" {
t.Error("Unexpected RatingPlanID: ", reply.RatingPlanID)
} else if *reply.EventCost.Cost != 6.5118 {
t.Error("Unexpected Cost: ", *reply.EventCost.Cost)
} else if *reply.EventCost.Usage != time.Duration(time.Hour) {
t.Error("Unexpected Usage: ", *reply.EventCost.Usage)
}
}
// we need to discuss about this case
// because 1003 have the following DestinationRate
// DR_1003_MAXCOST_DISC,DST_1003,RT_1CNT_PER_SEC,*up,4,0.12,*disconnect
func testAPIerGetRatingPlanCost2(t *testing.T) {
arg := &utils.RatingPlanCostArg{
Destination: "1003",
RatingPlanIDs: []string{"RP_1001", "RP_1002"},
SetupTime: utils.META_NOW,
Usage: "1h",
}
var reply dispatchers.RatingPlanCost
if err := apierRPC.Call(utils.RALsV1GetRatingPlansCost, arg, &reply); err != nil {
t.Error(err)
} else if reply.RatingPlanID != "RP_1001" {
t.Error("Unexpected RatingPlanID: ", reply.RatingPlanID)
} else if *reply.EventCost.Cost != 36 {
t.Error("Unexpected Cost: ", *reply.EventCost.Cost)
} else if *reply.EventCost.Usage != time.Duration(time.Hour) {
t.Error("Unexpected Usage: ", *reply.EventCost.Usage)
}
}
func testAPIerGetRatingPlanCost3(t *testing.T) {
arg := &utils.RatingPlanCostArg{
Destination: "1001",
RatingPlanIDs: []string{"RP_1001", "RP_1002"},
SetupTime: utils.META_NOW,
Usage: "1h",
}
var reply dispatchers.RatingPlanCost
if err := apierRPC.Call(utils.RALsV1GetRatingPlansCost, arg, &reply); err != nil {
t.Error(err)
} else if reply.RatingPlanID != "RP_1002" {
t.Error("Unexpected RatingPlanID: ", reply.RatingPlanID)
} else if *reply.EventCost.Cost != 36 {
t.Error("Unexpected Cost: ", *reply.EventCost.Cost)
} else if *reply.EventCost.Usage != time.Duration(time.Hour) {
t.Error("Unexpected Usage: ", *reply.EventCost.Usage)
}
}
func testAPIerKillEngine(t *testing.T) {
if err := engine.KillEngine(*waitRater); err != nil {
t.Error(err)

View File

@@ -84,7 +84,10 @@ func (rsv1 *RALsV1) GetRatingPlansCost(arg *utils.RatingPlanCostArg, reply *disp
engine.Cache.Remove(utils.CacheRatingProfiles, rPrfl.Id,
true, utils.NonTransactional) // Remove here so we don't overload memory
if err != nil {
if err != utils.ErrNotFound {
// in case we have UnauthorizedDestination
// or NotFound try next RatingPlan
if err != utils.ErrUnauthorizedDestination &&
err != utils.ErrNotFound {
return err
}
continue