diff --git a/engine/calldesc.go b/engine/calldesc.go index bf61cc4a2..755a0a61f 100644 --- a/engine/calldesc.go +++ b/engine/calldesc.go @@ -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, + } +} diff --git a/engine/calldesc_test.go b/engine/calldesc_test.go index c5424d058..1e6ceb7db 100644 --- a/engine/calldesc_test.go +++ b/engine/calldesc_test.go @@ -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()