mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
get max session duration method was modifing call descriptor
This commit is contained in:
@@ -424,7 +424,8 @@ and will decrease it by 10% for nine times. So if the user has little credit it
|
||||
If the user has no credit then it will return 0.
|
||||
If the user has postpayed plan it returns -1.
|
||||
*/
|
||||
func (cd *CallDescriptor) GetMaxSessionDuration() (time.Duration, error) {
|
||||
func (origCd *CallDescriptor) GetMaxSessionDuration() (time.Duration, error) {
|
||||
cd := origCd.Clone()
|
||||
if cd.CallDuration == 0 {
|
||||
cd.CallDuration = cd.TimeEnd.Sub(cd.TimeStart)
|
||||
}
|
||||
@@ -614,3 +615,22 @@ func (cd *CallDescriptor) CreateCallCost() *CallCost {
|
||||
Destination: cd.Destination,
|
||||
}
|
||||
}
|
||||
|
||||
func (cd *CallDescriptor) Clone() *CallDescriptor {
|
||||
return &CallDescriptor{
|
||||
Direction: cd.Direction,
|
||||
TOR: cd.TOR,
|
||||
Tenant: cd.Tenant,
|
||||
Subject: cd.Subject,
|
||||
Account: cd.Account,
|
||||
Destination: cd.Destination,
|
||||
TimeStart: cd.TimeStart,
|
||||
TimeEnd: cd.TimeEnd,
|
||||
LoopIndex: cd.LoopIndex,
|
||||
CallDuration: cd.CallDuration,
|
||||
Amount: cd.Amount,
|
||||
FallbackSubject: cd.FallbackSubject,
|
||||
RatingInfos: cd.RatingInfos,
|
||||
Increments: cd.Increments,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ package engine
|
||||
|
||||
import (
|
||||
"log"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -335,6 +336,23 @@ func TestMaxSessionTimeNoCredit(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestMaxSessionModifiesCallDesc(t *testing.T) {
|
||||
cd := &CallDescriptor{
|
||||
TimeStart: time.Date(2013, 10, 21, 18, 34, 0, 0, time.UTC),
|
||||
TimeEnd: time.Date(2013, 10, 21, 18, 35, 0, 0, time.UTC),
|
||||
Direction: "*out",
|
||||
TOR: "0",
|
||||
Tenant: "vdf",
|
||||
Subject: "broker",
|
||||
Destination: "0723",
|
||||
Amount: 5400}
|
||||
initial := cd.Clone()
|
||||
cd.GetMaxSessionDuration()
|
||||
if !reflect.DeepEqual(cd, initial) {
|
||||
t.Errorf("GetMaxSessionDuration is changing the call descriptor %+v != %+v", cd, initial)
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************** BENCHMARKS ***************************************/
|
||||
func BenchmarkStorageGetting(b *testing.B) {
|
||||
b.StopTimer()
|
||||
|
||||
Reference in New Issue
Block a user