From 2d8bf200d0941507e527b2338db61cfd756a69eb Mon Sep 17 00:00:00 2001 From: TeoV Date: Fri, 21 Jun 2019 11:19:38 +0300 Subject: [PATCH] Correct usage when SessionSv1.ProcessEvent for *postpaid and *rated --- apier/v1/sessionsv1_it_test.go | 10 ++++------ sessions/sessions.go | 7 ++++++- utils/consts.go | 3 ++- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/apier/v1/sessionsv1_it_test.go b/apier/v1/sessionsv1_it_test.go index 47508ab99..6fcc324d9 100644 --- a/apier/v1/sessionsv1_it_test.go +++ b/apier/v1/sessionsv1_it_test.go @@ -59,8 +59,8 @@ var ( testSSv1ItProcessCDR, testSSv1ItProcessEvent, testSSv1ItCDRsGetCdrs, - // testSSv1ItForceUpdateSession, - // testSSv1ItDynamicDebit, + testSSv1ItForceUpdateSession, + testSSv1ItDynamicDebit, testSSv1ItStopCgrEngine, } ) @@ -88,6 +88,7 @@ func TestSSv1ItWithPrepaid(t *testing.T) { func TestSSv1ItWithPostPaid(t *testing.T) { sSV1RequestType = utils.META_POSTPAID + sTestSessionSv1 = append(sTestSessionSv1[:len(sTestSessionSv1)-3], testSSv1ItStopCgrEngine) for _, stest := range sTestSessionSv1 { t.Run(sSV1RequestType, stest) } @@ -95,6 +96,7 @@ func TestSSv1ItWithPostPaid(t *testing.T) { func TestSSv1ItWithRated(t *testing.T) { sSV1RequestType = utils.META_RATED + sTestSessionSv1 = append(sTestSessionSv1[:len(sTestSessionSv1)-3], testSSv1ItStopCgrEngine) for _, stest := range sTestSessionSv1 { t.Run(sSV1RequestType, stest) } @@ -633,10 +635,6 @@ func testSSv1ItProcessEvent(t *testing.T) { }, }, } - if sSV1RequestType == utils.META_POSTPAID || - sSV1RequestType == utils.META_RATED { - eAttrs.CGREvent.Event[utils.Usage] = -1.0 - } if !reflect.DeepEqual(eAttrs, rply.Attributes) { t.Errorf("expecting: %+v, received: %+v", utils.ToJSON(eAttrs), utils.ToJSON(rply.Attributes)) diff --git a/sessions/sessions.go b/sessions/sessions.go index 1cfa1bb1a..ccfd82b4c 100644 --- a/sessions/sessions.go +++ b/sessions/sessions.go @@ -1500,7 +1500,12 @@ func (sS *SessionS) chargeEvent(tnt string, ev *engine.SafEvent, argDisp *utils. } return } - if errEnd := sS.endSession(s, utils.DurationPointer(maxUsage), nil, nil); errEnd != nil { + usage := maxUsage + if utils.IsSliceMember(utils.PostPaidRatedSlice, ev.GetStringIgnoreErrors(utils.RequestType)) { + usage = ev.GetDurationIgnoreErrors(utils.Usage) + } + //in case of postpaid and rated maxUsage = usage from event + if errEnd := sS.endSession(s, utils.DurationPointer(usage), nil, nil); errEnd != nil { utils.Logger.Warning( fmt.Sprintf("<%s> error when ending charged event: <%s>, err: <%s>", utils.SessionS, cgrID, err.Error())) diff --git a/utils/consts.go b/utils/consts.go index c5d80bc5d..c4e3d7bfa 100755 --- a/utils/consts.go +++ b/utils/consts.go @@ -28,7 +28,8 @@ var ( PreRated, CostSource, CostDetails, ExtraInfo, OrderID} CDRCFileFormats = []string{MetaFileCSV, MetaFScsv, MetaKamFlatstore, MetaOsipsFlatstore, MetaPartialCSV, MetaFileFWV, MetaFileXML} - MainCDRFieldsMap StringMap + PostPaidRatedSlice = []string{META_POSTPAID, META_RATED} + MainCDRFieldsMap StringMap GitLastLog string // If set, it will be processed as part of versioning PosterTransportContentTypes = map[string]string{