mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-12 02:26:26 +05:00
Added integration test for dynamic debit interval
This commit is contained in:
committed by
Dan Christian Bogos
parent
c0db74316c
commit
98ddf46256
@@ -737,34 +737,11 @@ func TestSSv1ItForceUpdateSession(t *testing.T) {
|
||||
} else if acnt.BalanceMap[utils.MONETARY].GetTotalValue() != eAcntVal {
|
||||
t.Errorf("Expected: %f, received: %f", eAcntVal, acnt.BalanceMap[utils.MONETARY].GetTotalValue())
|
||||
}
|
||||
|
||||
// argst := &sessions.V1TerminateSessionArgs{
|
||||
// TerminateSession: true,
|
||||
// ReleaseResources: true,
|
||||
// CGREvent: utils.CGREvent{
|
||||
// Tenant: "cgrates.org",
|
||||
// ID: "TestSSv1ItUpdateSession",
|
||||
// Event: map[string]interface{}{
|
||||
// utils.Tenant: "cgrates.org",
|
||||
// utils.Category: "call",
|
||||
// utils.ToR: utils.VOICE,
|
||||
// utils.OriginID: "TestSSv1It1",
|
||||
// utils.RequestType: utils.META_PREPAID,
|
||||
// utils.Account: "1001",
|
||||
// utils.Subject: "ANY2CNT",
|
||||
// utils.Destination: "1002",
|
||||
// utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
|
||||
// utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),
|
||||
// utils.Usage: 10 * time.Minute,
|
||||
// },
|
||||
// },
|
||||
// }
|
||||
rplyt := ""
|
||||
if err := sSv1BiRpc.Call(utils.SessionSv1ForceDisconnect,
|
||||
map[string]string{utils.OriginID: "TestSSv1It1"}, &rplyt); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if rplyt != utils.OK {
|
||||
} else if rplyt != utils.OK {
|
||||
t.Errorf("Unexpected reply: %s", rplyt)
|
||||
}
|
||||
aSessions = make([]*sessions.ActiveSession, 0)
|
||||
@@ -779,6 +756,114 @@ func TestSSv1ItForceUpdateSession(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSSv1ItDynamicDebit(t *testing.T) {
|
||||
attrSetBalance := utils.AttrSetBalance{
|
||||
Tenant: "cgrates.org",
|
||||
Account: "TestDynamicDebit",
|
||||
BalanceType: utils.VOICE,
|
||||
BalanceID: utils.StringPointer("TestDynamicDebitBalance"),
|
||||
Value: utils.Float64Pointer(2 * float64(time.Second)),
|
||||
RatingSubject: utils.StringPointer("*zero5ms")}
|
||||
var reply string
|
||||
if err := sSApierRpc.Call("ApierV2.SetBalance", attrSetBalance, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.OK {
|
||||
t.Errorf("Received: %s", reply)
|
||||
}
|
||||
var acnt *engine.Account
|
||||
attrs := &utils.AttrGetAccount{
|
||||
Tenant: attrSetBalance.Tenant,
|
||||
Account: attrSetBalance.Account,
|
||||
}
|
||||
eAcntVal := 2 * float64(time.Second)
|
||||
if err := sSApierRpc.Call("ApierV2.GetAccount", attrs, &acnt); err != nil {
|
||||
t.Error(err)
|
||||
} else if acnt.BalanceMap[utils.VOICE].GetTotalValue() != eAcntVal {
|
||||
t.Errorf("Expecting: %v, received: %v",
|
||||
time.Duration(eAcntVal), time.Duration(acnt.BalanceMap[utils.VOICE].GetTotalValue()))
|
||||
}
|
||||
|
||||
args1 := &sessions.V1InitSessionArgs{
|
||||
InitSession: true,
|
||||
GetAttributes: true,
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "TestSSv1ItInitiateSession",
|
||||
Event: map[string]interface{}{
|
||||
utils.Tenant: "cgrates.org",
|
||||
utils.Category: "call",
|
||||
utils.ToR: utils.VOICE,
|
||||
utils.OriginID: "TestDynamicTDebit",
|
||||
utils.RequestType: utils.META_PREPAID,
|
||||
utils.Account: "TestDynamicDebit",
|
||||
utils.Subject: "TEST",
|
||||
utils.Destination: "TEST",
|
||||
utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
|
||||
utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),
|
||||
utils.Usage: 0,
|
||||
utils.CGRDebitInterval: 30 * time.Millisecond,
|
||||
},
|
||||
},
|
||||
}
|
||||
var rply1 sessions.V1InitSessionReply
|
||||
if err := sSv1BiRpc.Call(utils.SessionSv1InitiateSession,
|
||||
args1, &rply1); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
} else if *rply1.MaxUsage != -1 {
|
||||
t.Errorf("Unexpected MaxUsage: %v", rply1.MaxUsage)
|
||||
}
|
||||
|
||||
aSessions := make([]*sessions.ActiveSession, 0)
|
||||
if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, nil, &aSessions); err != nil {
|
||||
t.Error(err)
|
||||
} else if len(aSessions) != 2 {
|
||||
t.Errorf("wrong active sessions: %s", utils.ToJSON(aSessions))
|
||||
}
|
||||
time.Sleep(time.Millisecond)
|
||||
eAcntVal -= float64(time.Millisecond) * 30 * 2 // 2 session
|
||||
if err := sSApierRpc.Call("ApierV2.GetAccount", attrs, &acnt); err != nil {
|
||||
t.Error(err)
|
||||
} else if acnt.BalanceMap[utils.VOICE].GetTotalValue() != eAcntVal {
|
||||
t.Errorf("Expecting: %v, received: %v",
|
||||
time.Duration(eAcntVal), time.Duration(acnt.BalanceMap[utils.VOICE].GetTotalValue()))
|
||||
}
|
||||
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
if err := sSApierRpc.Call("ApierV2.GetAccount", attrs, &acnt); err != nil {
|
||||
t.Error(err)
|
||||
} else if acnt.BalanceMap[utils.VOICE].GetTotalValue() != eAcntVal {
|
||||
t.Errorf("Expecting: %v, received: %v",
|
||||
time.Duration(eAcntVal), time.Duration(acnt.BalanceMap[utils.VOICE].GetTotalValue()))
|
||||
}
|
||||
time.Sleep(20 * time.Millisecond)
|
||||
eAcntVal -= float64(time.Millisecond) * 30 * 2 // 2 session
|
||||
if err := sSApierRpc.Call("ApierV2.GetAccount", attrs, &acnt); err != nil {
|
||||
t.Error(err)
|
||||
} else if acnt.BalanceMap[utils.VOICE].GetTotalValue() != eAcntVal {
|
||||
t.Errorf("Expecting: %v, received: %v",
|
||||
time.Duration(eAcntVal), time.Duration(acnt.BalanceMap[utils.VOICE].GetTotalValue()))
|
||||
}
|
||||
|
||||
if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, nil, &aSessions); err != nil {
|
||||
t.Error(err)
|
||||
} else if len(aSessions) != 2 {
|
||||
t.Errorf("wrong active sessions: %s", utils.ToJSON(aSessions))
|
||||
}
|
||||
rplyt := ""
|
||||
if err := sSv1BiRpc.Call(utils.SessionSv1ForceDisconnect,
|
||||
nil, &rplyt); err != nil {
|
||||
t.Error(err)
|
||||
} else if rplyt != utils.OK {
|
||||
t.Errorf("Unexpected reply: %s", rplyt)
|
||||
}
|
||||
aSessions = make([]*sessions.ActiveSession, 0)
|
||||
if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, nil, &aSessions); err == nil ||
|
||||
err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSSv1ItStopCgrEngine(t *testing.T) {
|
||||
if err := sSv1BiRpc.Close(); err != nil { // Close the connection so we don't get EOF warnings from client
|
||||
t.Error(err)
|
||||
|
||||
Reference in New Issue
Block a user