Updated sessions tests

This commit is contained in:
Trial97
2019-11-13 10:53:23 +02:00
committed by Dan Christian Bogos
parent ac5c0b0dfc
commit deaca56575
5 changed files with 30 additions and 41 deletions

View File

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

View File

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

View File

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

View File

@@ -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 {

View File

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