From 84e82dd83f627acfc6dad28aa87076a9b0871267 Mon Sep 17 00:00:00 2001 From: adragusin Date: Thu, 14 Nov 2019 14:49:44 +0200 Subject: [PATCH] Updated session replication with automatic debit test --- .../session_replications_automaticdebit_it_test.go | 10 ++++++++++ sessions/session.go | 3 +++ sessions/session_test.go | 4 ++++ 3 files changed, 17 insertions(+) diff --git a/general_tests/session_replications_automaticdebit_it_test.go b/general_tests/session_replications_automaticdebit_it_test.go index 1da5d3495..787751926 100644 --- a/general_tests/session_replications_automaticdebit_it_test.go +++ b/general_tests/session_replications_automaticdebit_it_test.go @@ -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 diff --git a/sessions/session.go b/sessions/session.go index f58a8a9c5..df33a23ba 100644 --- a/sessions/session.go +++ b/sessions/session.go @@ -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 diff --git a/sessions/session_test.go b/sessions/session_test.go index 77fda32ee..99d53958a 100644 --- a/sessions/session_test.go +++ b/sessions/session_test.go @@ -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")