Updated session replication with automatic debit test

This commit is contained in:
adragusin
2019-11-14 14:49:44 +02:00
committed by Dan Christian Bogos
parent 663cd77f89
commit 84e82dd83f
3 changed files with 17 additions and 0 deletions

View File

@@ -206,6 +206,8 @@ func testSessionSRplInitiate(t *testing.T) {
t.Errorf("Expecting : ~%+v, received: %+v", 10*time.Millisecond, aSessions[0].Usage) //here
}
//check passive session
var autoDebit1, autoDebit2 time.Time
var pSessions []*sessions.ExternalSession
if err := smgRplcSlvRPC.Call(utils.SessionSv1GetPassiveSessions,
utils.SessionFilter{
@@ -218,7 +220,10 @@ func testSessionSRplInitiate(t *testing.T) {
t.Errorf("PassiveSessions: %+v", pSessions)
} else if pSessions[0].Usage < 5*time.Millisecond || pSessions[0].Usage > 15*time.Millisecond {
t.Errorf("Expecting : %+v, received: %+v", 10*time.Millisecond, pSessions[0].Usage)
} else if autoDebit1 = pSessions[0].NextAutoDebit; autoDebit1.IsZero() {
t.Errorf("unexpected NextAutoDebit: %s", utils.ToIJSON(aSessions[0]))
}
//check active session (II)
time.Sleep(10 * time.Millisecond)
if err := smgRplcMstrRPC.Call(utils.SessionSv1GetActiveSessions,
@@ -234,6 +239,7 @@ func testSessionSRplInitiate(t *testing.T) {
} else if aSessions[0].Usage < 15*time.Millisecond || aSessions[0].Usage > 25*time.Millisecond {
t.Errorf("Expecting : ~%+v, received: %+v", 20*time.Millisecond, aSessions[0].Usage) //here
}
//check passive session (II)
if err := smgRplcSlvRPC.Call(utils.SessionSv1GetPassiveSessions,
utils.SessionFilter{
@@ -246,6 +252,10 @@ func testSessionSRplInitiate(t *testing.T) {
t.Errorf("PassiveSessions: %+v", pSessions)
} else if pSessions[0].Usage < 15*time.Millisecond || pSessions[0].Usage > 25*time.Millisecond {
t.Errorf("Expecting : %+v, received: %+v", 20*time.Millisecond, pSessions[0].Usage)
} else if autoDebit2 = pSessions[0].NextAutoDebit; autoDebit2.IsZero() {
t.Errorf("unexpected NextAutoDebit: %s", utils.ToIJSON(aSessions[0]))
} else if autoDebit1 == autoDebit2 {
t.Error("Expecting NextAutoDebit to be different from the previous one")
}
//get balance

View File

@@ -164,6 +164,9 @@ func (s *Session) AsExternalSession(sr *SRun, tmz, nodeID string) (aS *ExternalS
NodeID: nodeID,
DebitInterval: s.DebitInterval,
}
if sr.NextAutoDebit != nil {
aS.NextAutoDebit = *sr.NextAutoDebit
}
if sr.CD != nil {
aS.LoopIndex = sr.CD.LoopIndex
aS.DurationIndex = sr.CD.DurationIndex

View File

@@ -595,6 +595,8 @@ func TestSessionAsExternalSessions3(t *testing.T) {
utils.Usage: time.Duration(2 * time.Second),
utils.Cost: 12.13,
}
tTime := time.Date(2020, time.April, 18, 23, 0, 0, 0, time.UTC)
s := &Session{
CGRID: "RandomCGRID",
Tenant: "cgrates.org",
@@ -611,6 +613,7 @@ func TestSessionAsExternalSessions3(t *testing.T) {
MaxRateUnit: 30 * time.Second,
MaxCostSoFar: 20,
},
NextAutoDebit: &tTime,
},
},
}
@@ -640,6 +643,7 @@ func TestSessionAsExternalSessions3(t *testing.T) {
MaxRate: 11,
MaxRateUnit: 30 * time.Second,
MaxCostSoFar: 20,
NextAutoDebit: tTime,
}
//check for some fields if populated correct
rply := s.AsExternalSession(s.SRuns[0], "", "ALL")