From 5d7db1db47230d8e605bc7286c7dbeb0f9cf2ba2 Mon Sep 17 00:00:00 2001 From: TeoV Date: Mon, 29 Jul 2019 16:45:55 +0300 Subject: [PATCH] In case we have UnauthorizedDestination error in GetRatingPlansCost we go to next RatingPlan --- apier/v1/apier2_it_test.go | 65 ++++++++++++++++++++++++++++++++++++++ apier/v1/rals.go | 5 ++- 2 files changed, 69 insertions(+), 1 deletion(-) diff --git a/apier/v1/apier2_it_test.go b/apier/v1/apier2_it_test.go index 9e4555d64..1a747d490 100644 --- a/apier/v1/apier2_it_test.go +++ b/apier/v1/apier2_it_test.go @@ -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) diff --git a/apier/v1/rals.go b/apier/v1/rals.go index 83207b25f..62ad9b9b9 100644 --- a/apier/v1/rals.go +++ b/apier/v1/rals.go @@ -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