get max session duration method was modifing call descriptor

This commit is contained in:
Radu Ioan Fericean
2014-02-07 19:10:44 +02:00
parent aa99a1e526
commit dadf06f3ef
2 changed files with 39 additions and 1 deletions

View File

@@ -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,
}
}

View File

@@ -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()