integration tests fixes

This commit is contained in:
Radu Ioan Fericean
2016-03-04 20:56:09 +02:00
parent ce8f7bf927
commit 47778f398d
8 changed files with 43 additions and 28 deletions

View File

@@ -623,7 +623,7 @@ func TestDmtAgentCdrs(t *testing.T) {
if cdrs[0].Usage != "610" {
t.Errorf("Unexpected CDR Usage received, cdr: %+v ", cdrs[0])
}
if cdrs[0].Cost != 0.795 {
if cdrs[0].Cost != 0.7565 {
t.Errorf("Unexpected CDR Cost received, cdr: %+v ", cdrs[0])
}
}

View File

@@ -151,7 +151,7 @@ func TestSMGV1GetMaxUsage(t *testing.T) {
var maxTime float64
if err := smgV1Rpc.Call("SMGenericV1.GetMaxUsage", setupReq, &maxTime); err != nil {
t.Error(err)
} else if maxTime != 2690 {
} else if maxTime != 2700 {
t.Errorf("Calling ApierV2.MaxUsage got maxTime: %f", maxTime)
}
}

View File

@@ -201,20 +201,23 @@ func (cc *CallCost) Round() {
ts.RateInterval.Rating.RoundingMethod)
correctionCost := roundedCost - cost
//log.Print(cost, roundedCost, correctionCost)
roundInc := &Increment{
Cost: correctionCost,
BalanceInfo: inc.BalanceInfo,
if correctionCost != 0 {
ts.RoundIncrement = &Increment{
Cost: correctionCost,
BalanceInfo: inc.BalanceInfo,
}
totalCorrectionCost += correctionCost
ts.Cost += correctionCost
}
totalCorrectionCost += correctionCost
ts.Cost += correctionCost
ts.RoundIncrements = append(ts.RoundIncrements, roundInc)
}
cc.Cost += totalCorrectionCost
}
func (cc *CallCost) GetRoundIncrements() (roundIncrements Increments) {
for _, ts := range cc.Timespans {
roundIncrements = append(roundIncrements, ts.RoundIncrements...)
if ts.RoundIncrement != nil && ts.RoundIncrement.Cost != 0 {
roundIncrements = append(roundIncrements, ts.RoundIncrement)
}
}
return
}

View File

@@ -682,9 +682,12 @@ func (cd *CallDescriptor) debit(account *Account, dryRun bool, goNegative bool)
}
if cd.PerformRounding {
cc.Round()
rcd := cc.CreateCallDescriptor()
rcd.Increments = cc.GetRoundIncrements()
rcd.RefundRounding()
roundIncrements := cc.GetRoundIncrements()
if len(roundIncrements) != 0 {
rcd := cc.CreateCallDescriptor()
rcd.Increments = roundIncrements
rcd.RefundRounding()
}
}
//log.Printf("OUT CC: ", cc)
return

View File

@@ -36,7 +36,7 @@ type TimeSpan struct {
RateInterval *RateInterval
DurationIndex time.Duration // the call duration so far till TimeEnd
Increments Increments
RoundIncrements Increments
RoundIncrement *Increment
MatchedSubject, MatchedPrefix, MatchedDestId, RatingPlanId string
CompressFactor int
ratingInfo *RatingInfo

View File

@@ -230,11 +230,14 @@ func (s *Session) SaveOperations() {
firstCC.Timespans.Compress()
firstCC.Round()
cd := firstCC.CreateCallDescriptor()
cd.Increments = firstCC.GetRoundIncrements()
var response float64
if err := s.sessionManager.Rater().RefundRounding(cd, &response); err != nil {
utils.Logger.Err(fmt.Sprintf("<SM> ERROR failed to refund rounding: %v", err))
roundIncrements := firstCC.GetRoundIncrements()
if len(roundIncrements) != 0 {
cd := firstCC.CreateCallDescriptor()
cd.Increments = roundIncrements
var response float64
if err := s.sessionManager.Rater().RefundRounding(cd, &response); err != nil {
utils.Logger.Err(fmt.Sprintf("<SM> ERROR failed to refund rounding: %v", err))
}
}
var reply string
err := s.sessionManager.CdrSrv().LogCallCost(&engine.CallCostLog{

View File

@@ -205,11 +205,14 @@ func (self *SMGSession) saveOperations() error {
}
firstCC.Timespans.Compress()
firstCC.Round()
cd := firstCC.CreateCallDescriptor()
cd.Increments = firstCC.GetRoundIncrements()
var response float64
if err := self.rater.RefundRounding(cd, &response); err != nil {
return err
roundIncrements := firstCC.GetRoundIncrements()
if len(roundIncrements) != 0 {
cd := firstCC.CreateCallDescriptor()
cd.Increments = roundIncrements
var response float64
if err := self.rater.RefundRounding(cd, &response); err != nil {
return err
}
}
var reply string

View File

@@ -278,11 +278,14 @@ func (self *SMGeneric) ChargeEvent(gev SMGenericEvent, clnt *rpc2.Client) (maxDu
}
}
cc.Round()
cd := cc.CreateCallDescriptor()
cd.Increments = cc.GetRoundIncrements()
var response float64
if err := self.rater.RefundRounding(cd, &response); err != nil {
utils.Logger.Err(fmt.Sprintf("<SM> ERROR failed to refund rounding: %v", err))
roundIncrements := cc.GetRoundIncrements()
if len(roundIncrements) != 0 {
cd := cc.CreateCallDescriptor()
cd.Increments = roundIncrements
var response float64
if err := self.rater.RefundRounding(cd, &response); err != nil {
utils.Logger.Err(fmt.Sprintf("<SM> ERROR failed to refund rounding: %v", err))
}
}
var reply string