From deaca56575f1d840ac48a53e13de4952a96a501c Mon Sep 17 00:00:00 2001 From: Trial97 Date: Wed, 13 Nov 2019 10:53:23 +0200 Subject: [PATCH] Updated sessions tests --- apier/v1/sessions_process_event_it_test.go | 16 +++----- apier/v1/sessionsv1_it_test.go | 40 ++++++++----------- ...ion_replications_automaticdebit_it_test.go | 5 ++- sessions/sessions.go | 6 +-- sessions/sessions_birpc_it_test.go | 4 +- 5 files changed, 30 insertions(+), 41 deletions(-) diff --git a/apier/v1/sessions_process_event_it_test.go b/apier/v1/sessions_process_event_it_test.go index 571a212f2..59c2a5a67 100644 --- a/apier/v1/sessions_process_event_it_test.go +++ b/apier/v1/sessions_process_event_it_test.go @@ -189,11 +189,9 @@ func testSSv1ItProcessEventInitiateSession(t *testing.T) { t.Error(err) } // in case of prepaid and pseudoprepade we expect a MaxUsage of 5min - // and in case of postpaid and rated we expect -1 - if ((sSV1RequestType == utils.META_PREPAID || - sSV1RequestType == utils.META_PSEUDOPREPAID) && *rply.MaxUsage != initUsage) || - ((sSV1RequestType == utils.META_POSTPAID || - sSV1RequestType == utils.META_RATED) && *rply.MaxUsage != -1) { + // and in case of postpaid and rated we expect the value of Usage field + // if this was missing the MaxUsage should be equal to MaxCallDuration from config + if *rply.MaxUsage != initUsage { t.Errorf("Unexpected MaxUsage: %v", rply.MaxUsage) } if *rply.ResourceMessage != "RES_ACNT_1001" { @@ -285,11 +283,9 @@ func testSSv1ItProcessEventUpdateSession(t *testing.T) { utils.ToJSON(eAttrs), utils.ToJSON(rply.Attributes)) } // in case of prepaid and pseudoprepade we expect a MaxUsage of 5min - // and in case of postpaid and rated we expect -1 - if ((sSV1RequestType == utils.META_PREPAID || - sSV1RequestType == utils.META_PSEUDOPREPAID) && *rply.MaxUsage != reqUsage) || - ((sSV1RequestType == utils.META_POSTPAID || - sSV1RequestType == utils.META_RATED) && *rply.MaxUsage != -1) { + // and in case of postpaid and rated we expect the value of Usage field + // if this was missing the MaxUsage should be equal to MaxCallDuration from config + if *rply.MaxUsage != reqUsage { t.Errorf("Unexpected MaxUsage: %v", rply.MaxUsage) } aSessions := make([]*sessions.ExternalSession, 0) diff --git a/apier/v1/sessionsv1_it_test.go b/apier/v1/sessionsv1_it_test.go index 4b38f701b..a4eaf5d50 100644 --- a/apier/v1/sessionsv1_it_test.go +++ b/apier/v1/sessionsv1_it_test.go @@ -334,11 +334,9 @@ func testSSv1ItInitiateSession(t *testing.T) { t.Fatal(err) } // in case of prepaid and pseudoprepade we expect a MaxUsage of 5min - // and in case of postpaid and rated we expect -1 - if ((sSV1RequestType == utils.META_PREPAID || - sSV1RequestType == utils.META_PSEUDOPREPAID) && *rply.MaxUsage != initUsage) || - ((sSV1RequestType == utils.META_POSTPAID || - sSV1RequestType == utils.META_RATED) && *rply.MaxUsage != -1) { + // and in case of postpaid and rated we expect the value of Usage field + // if this was missing the MaxUsage should be equal to MaxCallDuration from config + if *rply.MaxUsage != initUsage { t.Errorf("Unexpected MaxUsage: %v", rply.MaxUsage) } if *rply.ResourceAllocation != "RES_ACNT_1001" { @@ -407,12 +405,10 @@ func testSSv1ItInitiateSessionWithDigest(t *testing.T) { t.Fatal(err) } // in case of prepaid and pseudoprepade we expect a MaxUsage of 5min - // and in case of postpaid and rated we expect -1 - if ((sSV1RequestType == utils.META_PREPAID || - sSV1RequestType == utils.META_PSEUDOPREPAID) && *rply.MaxUsage != initUsage.Seconds()) || - ((sSV1RequestType == utils.META_POSTPAID || - sSV1RequestType == utils.META_RATED) && *rply.MaxUsage != -1) { - t.Errorf("Unexpected MaxUsage: %v", rply.MaxUsage) + // and in case of postpaid and rated we expect the value of Usage field + // if this was missing the MaxUsage should be equal to MaxCallDuration from config + if *rply.MaxUsage != initUsage.Seconds() { + t.Errorf("Unexpected MaxUsage: %v", *rply.MaxUsage) } if *rply.ResourceAllocation != "RES_ACNT_1001" { t.Errorf("Unexpected ResourceAllocation: %s", *rply.ResourceAllocation) @@ -484,12 +480,10 @@ func testSSv1ItUpdateSession(t *testing.T) { utils.ToJSON(eAttrs), utils.ToJSON(rply.Attributes)) } // in case of prepaid and pseudoprepade we expect a MaxUsage of 5min - // and in case of postpaid and rated we expect -1 - if ((sSV1RequestType == utils.META_PREPAID || - sSV1RequestType == utils.META_PSEUDOPREPAID) && *rply.MaxUsage != reqUsage) || - ((sSV1RequestType == utils.META_POSTPAID || - sSV1RequestType == utils.META_RATED) && *rply.MaxUsage != -1) { - t.Errorf("Unexpected MaxUsage: %v", rply.MaxUsage) + // and in case of postpaid and rated we expect the value of Usage field + // if this was missing the MaxUsage should be equal to MaxCallDuration from config + if *rply.MaxUsage != reqUsage { + t.Errorf("Unexpected MaxUsage: %v", *rply.MaxUsage) } aSessions := make([]*sessions.ExternalSession, 0) if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, nil, &aSessions); err != nil { @@ -593,12 +587,10 @@ func testSSv1ItProcessEvent(t *testing.T) { t.Fatal(err) } // in case of prepaid and pseudoprepade we expect a MaxUsage of 5min - // and in case of postpaid and rated we expect -1 - if ((sSV1RequestType == utils.META_PREPAID || - sSV1RequestType == utils.META_PSEUDOPREPAID) && *rply.MaxUsage != initUsage) || - ((sSV1RequestType == utils.META_POSTPAID || - sSV1RequestType == utils.META_RATED) && *rply.MaxUsage != -1) { - t.Errorf("Unexpected MaxUsage: %v", rply.MaxUsage) + // and in case of postpaid and rated we expect the value of Usage field + // if this was missing the MaxUsage should be equal to MaxCallDuration from config + if *rply.MaxUsage != initUsage { + t.Errorf("Unexpected MaxUsage: %v", *rply.MaxUsage) } if *rply.ResourceAllocation != "RES_ACNT_1001" { t.Errorf("Unexpected ResourceAllocation: %s", *rply.ResourceAllocation) @@ -892,7 +884,7 @@ func testSSv1ItDynamicDebit(t *testing.T) { args1, &rply1); err != nil { t.Error(err) return - } else if *rply1.MaxUsage != time.Duration(-1) { + } else if *rply1.MaxUsage != 3*time.Hour /* MaxCallDuration from config*/ { t.Errorf("Unexpected MaxUsage: %v", rply1.MaxUsage) } diff --git a/general_tests/session_replications_automaticdebit_it_test.go b/general_tests/session_replications_automaticdebit_it_test.go index e07fefa23..1da5d3495 100644 --- a/general_tests/session_replications_automaticdebit_it_test.go +++ b/general_tests/session_replications_automaticdebit_it_test.go @@ -185,8 +185,9 @@ func testSessionSRplInitiate(t *testing.T) { t.Error(err) } //compare the value - if *initRpl.MaxUsage != -1 { - t.Errorf("Expecting : %+v, received: %+v", -1, initRpl.MaxUsage) + eMaxUsage := 3 * time.Hour // MaxCallDuration from config + if *initRpl.MaxUsage != eMaxUsage { + t.Errorf("Expecting : %+v, received: %+v", eMaxUsage, initRpl.MaxUsage) } //check active session diff --git a/sessions/sessions.go b/sessions/sessions.go index 85b1043b9..1c37b2837 100644 --- a/sessions/sessions.go +++ b/sessions/sessions.go @@ -499,7 +499,7 @@ func (sS *SessionS) debitSession(s *Session, sRunIdx int, dur time.Duration, sr.CD.DurationIndex -= rDur sr.CD.DurationIndex += ccDuration sr.CD.MaxCostSoFar += cc.Cost - sr.CD.LoopIndex += 1 + sr.CD.LoopIndex++ sr.TotalUsage += sr.LastUsage ec := engine.NewEventCostFromCallCost(cc, s.CGRID, sr.Event.GetStringIgnoreErrors(utils.RunID)) @@ -2189,7 +2189,7 @@ func (sS *SessionS) BiRPCv1InitiateSession(clnt rpcclient.RpcClientConnection, if err != nil { return utils.NewErrRALs(err) } - if s.debitStop != nil { //active debit + if dbtItvl > 0 { //active debit rply.MaxUsage = utils.DurationPointer(sS.cgrCfg.SessionSCfg().MaxCallDuration) } else { if maxUsage, err := sS.updateSession(s, nil); err != nil { @@ -3087,7 +3087,7 @@ func (sS *SessionS) BiRPCv1ProcessEvent(clnt rpcclient.RpcClientConnection, if err != nil { return utils.NewErrRALs(err) } - if s.debitStop != nil { //active debit + if dbtItvl > 0 { //active debit rply.MaxUsage = utils.DurationPointer(sS.cgrCfg.SessionSCfg().MaxCallDuration) } else { if maxUsage, err := sS.updateSession(s, nil); err != nil { diff --git a/sessions/sessions_birpc_it_test.go b/sessions/sessions_birpc_it_test.go index 4761cff02..39f60ca26 100644 --- a/sessions/sessions_birpc_it_test.go +++ b/sessions/sessions_birpc_it_test.go @@ -160,7 +160,7 @@ func TestSessionsBiRPCSessionAutomaticDisconnects(t *testing.T) { t.Error(err) } time.Sleep(10 * time.Millisecond) // give some time to allow the session to be created - expMaxUsage := time.Duration(-1) + expMaxUsage := 3 * time.Hour // MaxCallDuration from config if *initRpl.MaxUsage != expMaxUsage { t.Errorf("Expecting : %+v, received: %+v", expMaxUsage, *initRpl.MaxUsage) } @@ -279,7 +279,7 @@ func TestSessionsBiRPCSessionOriginatorTerminate(t *testing.T) { t.Error(err) } - expMaxUsage := time.Duration(-1) + expMaxUsage := 3 * time.Hour // MaxCallDuration from config if *initRpl.MaxUsage != expMaxUsage { t.Errorf("Expecting : %+v, received: %+v", expMaxUsage, *initRpl.MaxUsage) }