[SessionS] Compile the SRun.EventCost before store it and send it further

This commit is contained in:
TeoV
2020-12-14 18:04:05 +02:00
committed by Dan Christian Bogos
parent 19f30a418d
commit 249fd7eec3
3 changed files with 29 additions and 1 deletions

View File

@@ -692,6 +692,13 @@ func testSSv1ItCDRsGetCdrs(t *testing.T) {
if cdrs[0].Cost != 0.198 {
t.Errorf("Unexpected cost for CDR: %f", cdrs[0].Cost)
}
if cdrs[0].CostDetails.Usage == nil || *cdrs[0].CostDetails.Usage != 10*time.Minute {
t.Errorf("Unexpected usage from CostDetails for CDR: %+v", cdrs[0].CostDetails.Usage)
}
if cdrs[0].CostDetails.Cost == nil || *cdrs[0].CostDetails.Cost != 0.198 {
t.Errorf("Unexpected cost from CostDetails for CDR: %+v", cdrs[0].CostDetails.Cost)
}
}
args = &utils.RPCCDRsFilterWithArgDispatcher{RPCCDRsFilter: &utils.RPCCDRsFilter{RunIDs: []string{"SupplierCharges"},
OriginIDs: []string{"TestSSv1It1"}}}
@@ -703,6 +710,12 @@ func testSSv1ItCDRsGetCdrs(t *testing.T) {
if cdrs[0].Cost != 0.102 {
t.Errorf("Unexpected cost for CDR: %f", cdrs[0].Cost)
}
if cdrs[0].CostDetails.Usage == nil || *cdrs[0].CostDetails.Usage != 10*time.Minute {
t.Errorf("Unexpected usage from CostDetails for CDR: %+v", cdrs[0].CostDetails.Usage)
}
if cdrs[0].CostDetails.Cost == nil || *cdrs[0].CostDetails.Cost != 0.102 {
t.Errorf("Unexpected cost from CostDetails for CDR: %+v", cdrs[0].CostDetails.Cost)
}
}
args = &utils.RPCCDRsFilterWithArgDispatcher{RPCCDRsFilter: &utils.RPCCDRsFilter{RunIDs: []string{"CustomerCharges"},
@@ -715,6 +728,12 @@ func testSSv1ItCDRsGetCdrs(t *testing.T) {
if cdrs[0].Cost != 0.099 {
t.Errorf("Unexpected cost for CDR: %f", cdrs[0].Cost)
}
if cdrs[0].CostDetails.Usage == nil || *cdrs[0].CostDetails.Usage != 5*time.Minute {
t.Errorf("Unexpected usage from CostDetails for CDR: %+v", cdrs[0].CostDetails.Usage)
}
if cdrs[0].CostDetails.Cost == nil || *cdrs[0].CostDetails.Cost != 0.099 {
t.Errorf("Unexpected cost from CostDetails for CDR: %+v", cdrs[0].CostDetails.Cost)
}
}
args = &utils.RPCCDRsFilterWithArgDispatcher{RPCCDRsFilter: &utils.RPCCDRsFilter{RunIDs: []string{"SupplierCharges"},
OriginIDs: []string{"TestSSv1It2"}}}
@@ -726,6 +745,12 @@ func testSSv1ItCDRsGetCdrs(t *testing.T) {
if cdrs[0].Cost != 0.051 {
t.Errorf("Unexpected cost for CDR: %f", cdrs[0].Cost)
}
if cdrs[0].CostDetails.Usage == nil || *cdrs[0].CostDetails.Usage != 5*time.Minute {
t.Errorf("Unexpected usage from CostDetails for CDR: %+v", cdrs[0].CostDetails.Usage)
}
if cdrs[0].CostDetails.Cost == nil || *cdrs[0].CostDetails.Cost != 0.051 {
t.Errorf("Unexpected cost from CostDetails for CDR: %+v", cdrs[0].CostDetails.Cost)
}
}
}

View File

@@ -4,6 +4,7 @@ cgrates (0.10.3~dev) UNRELEASED; urgency=medium
* [SessionS] Use rals_conns when sending refund rounding
* [SupplierS] SupplierS require a connection to rals when give
AccountIDs and RatingPlanIDs to calculate
* [SessionS] Compile the SRun.EventCost before store it and send it further
-- DanB <danb@cgrates.org> Thu, 08 Oct 2020 16:23:58 +0300

View File

@@ -1501,8 +1501,10 @@ func (sS *SessionS) endSession(s *Session, tUsage, lastUsage *time.Duration,
fmt.Sprintf("<%s> failed rounding session cost for <%s>, srIdx: <%d>, error: <%s>",
utils.SessionS, s.CGRID, sRunIdx, err.Error()))
}
}
// compute the event cost before saving the SessionCost
// add here to be applied for messages also
sr.EventCost.Compute()
if sS.cgrCfg.SessionSCfg().StoreSCosts {
if err := sS.storeSCost(s, sRunIdx); err != nil {
utils.Logger.Warning(