mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Update test from apier
This commit is contained in:
committed by
Dan Christian Bogos
parent
4e83f55bb2
commit
801d890d84
@@ -36,26 +36,23 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
sSv1CfgPath string
|
||||
sSv1Cfg *config.CGRConfig
|
||||
sSv1BiRpc *rpc2.Client
|
||||
sSApierRpc *rpc.Client
|
||||
disconnectEvChan = make(chan *utils.AttrDisconnectSession)
|
||||
sSv1CfgPath string
|
||||
sSv1Cfg *config.CGRConfig
|
||||
sSv1BiRpc *rpc2.Client
|
||||
sSApierRpc *rpc.Client
|
||||
)
|
||||
|
||||
var discEvChan = make(chan *utils.AttrDisconnectSession, 1)
|
||||
|
||||
func handleDisconnectSession(clnt *rpc2.Client,
|
||||
args *utils.AttrDisconnectSession, reply *string) error {
|
||||
time.Sleep(time.Second)
|
||||
disconnectEvChan <- args
|
||||
discEvChan <- args
|
||||
// free the channel
|
||||
<-discEvChan
|
||||
*reply = utils.OK
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleGetSessionIDs(clnt *rpc2.Client,
|
||||
ignParam string, sessionIDs *[]*sessions.SessionID) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestSSv1ItInitCfg(t *testing.T) {
|
||||
var err error
|
||||
sSv1CfgPath = path.Join(*dataDir, "conf", "samples", "sessions")
|
||||
@@ -87,15 +84,9 @@ func TestSSv1ItStartEngine(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSSv1ItRpcConn(t *testing.T) {
|
||||
clntHandlers := map[string]interface{}{utils.SessionSv1DisconnectSession: handleDisconnectSession}
|
||||
dummyClnt, err := utils.NewBiJSONrpcClient(sSv1Cfg.SessionSCfg().ListenBijson,
|
||||
nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
clntHandlers := map[string]interface{}{
|
||||
utils.SessionSv1DisconnectSession: handleDisconnectSession,
|
||||
utils.SessionSv1GetActiveSessionIDs: handleGetSessionIDs,
|
||||
}
|
||||
clntHandlers)
|
||||
if sSv1BiRpc, err = utils.NewBiJSONrpcClient(sSv1Cfg.SessionSCfg().ListenBijson,
|
||||
clntHandlers); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -653,241 +644,247 @@ func TestSSv1ItCDRsGetCdrs(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Disconnect session block
|
||||
// func TestSSv1ItForceUpdateSession(t *testing.T) {
|
||||
// aSessions := make([]*sessions.ActiveSession, 0)
|
||||
// if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, nil, &aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
// t.Errorf("Error: %v with len(asessions)=%v", err, len(aSessions))
|
||||
// }
|
||||
// var acnt *engine.Account
|
||||
// attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"}
|
||||
// eAcntVal := 9.3995
|
||||
// if err := sSApierRpc.Call("ApierV2.GetAccount", attrs, &acnt); err != nil {
|
||||
// t.Error(err)
|
||||
// } else if acnt.BalanceMap[utils.MONETARY].GetTotalValue() != eAcntVal {
|
||||
// t.Errorf("Expected: %f, received: %f", eAcntVal, acnt.BalanceMap[utils.MONETARY].GetTotalValue())
|
||||
// }
|
||||
func TestSSv1ItForceUpdateSession(t *testing.T) {
|
||||
var aSessions []*sessions.ActiveSession
|
||||
if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions,
|
||||
nil, &aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Errorf("Error: %v with len(asessions)=%v", err, len(aSessions))
|
||||
}
|
||||
var acnt *engine.Account
|
||||
attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"}
|
||||
eAcntVal := 9.3995
|
||||
if err := sSApierRpc.Call("ApierV2.GetAccount", attrs, &acnt); err != nil {
|
||||
t.Error(err)
|
||||
} else if acnt.BalanceMap[utils.MONETARY].GetTotalValue() != eAcntVal {
|
||||
t.Errorf("Expected: %f, received: %f", eAcntVal, acnt.BalanceMap[utils.MONETARY].GetTotalValue())
|
||||
}
|
||||
|
||||
// reqUsage := 5 * time.Minute
|
||||
// args := &sessions.V1UpdateSessionArgs{
|
||||
// GetAttributes: true,
|
||||
// UpdateSession: 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: "TestSSv1It",
|
||||
// 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: reqUsage,
|
||||
// },
|
||||
// },
|
||||
// }
|
||||
// var rply sessions.V1UpdateSessionReply
|
||||
// if err := sSv1BiRpc.Call(utils.SessionSv1UpdateSession,
|
||||
// args, &rply); err != nil {
|
||||
// t.Error(err)
|
||||
// }
|
||||
// eAttrs := &engine.AttrSProcessEventReply{
|
||||
// MatchedProfiles: []string{"ATTR_ACNT_1001"},
|
||||
// AlteredFields: []string{"OfficeGroup"},
|
||||
// CGREvent: &utils.CGREvent{
|
||||
// Tenant: "cgrates.org",
|
||||
// ID: "TestSSv1ItUpdateSession",
|
||||
// Context: utils.StringPointer(utils.MetaSessionS),
|
||||
// Event: map[string]interface{}{
|
||||
// utils.CGRID: "70876773b294f0e1476065f8d18bb9ec6bcb3d5f",
|
||||
// utils.Tenant: "cgrates.org",
|
||||
// utils.Category: "call",
|
||||
// utils.ToR: utils.VOICE,
|
||||
// utils.Account: "1001",
|
||||
// utils.Subject: "ANY2CNT",
|
||||
// utils.Destination: "1002",
|
||||
// "OfficeGroup": "Marketing",
|
||||
// utils.OriginID: "TestSSv1It",
|
||||
// utils.RequestType: utils.META_PREPAID,
|
||||
// utils.SetupTime: "2018-01-07T17:00:00Z",
|
||||
// utils.AnswerTime: "2018-01-07T17:00:10Z",
|
||||
// utils.Usage: 300000000000.0,
|
||||
// },
|
||||
// },
|
||||
// }
|
||||
// if !reflect.DeepEqual(eAttrs, rply.Attributes) {
|
||||
// t.Errorf("expecting: %+v, received: %+v",
|
||||
// utils.ToJSON(eAttrs), utils.ToJSON(rply.Attributes))
|
||||
// }
|
||||
// if *rply.MaxUsage != reqUsage {
|
||||
// t.Errorf("Unexpected MaxUsage: %v", rply.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 ssesions: %s", utils.ToJSON(aSessions))
|
||||
// }
|
||||
reqUsage := 5 * time.Minute
|
||||
args := &sessions.V1UpdateSessionArgs{
|
||||
GetAttributes: true,
|
||||
UpdateSession: 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: "TestSSv1It",
|
||||
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: reqUsage,
|
||||
},
|
||||
},
|
||||
}
|
||||
var rply sessions.V1UpdateSessionReply
|
||||
if err := sSv1BiRpc.Call(utils.SessionSv1UpdateSession,
|
||||
args, &rply); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
eAttrs := &engine.AttrSProcessEventReply{
|
||||
MatchedProfiles: []string{"ATTR_ACNT_1001"},
|
||||
AlteredFields: []string{"OfficeGroup"},
|
||||
CGREvent: &utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "TestSSv1ItUpdateSession",
|
||||
Context: utils.StringPointer(utils.MetaSessionS),
|
||||
Event: map[string]interface{}{
|
||||
utils.CGRID: "70876773b294f0e1476065f8d18bb9ec6bcb3d5f",
|
||||
utils.Tenant: "cgrates.org",
|
||||
utils.Category: "call",
|
||||
utils.ToR: utils.VOICE,
|
||||
utils.Account: "1001",
|
||||
utils.Subject: "ANY2CNT",
|
||||
utils.Destination: "1002",
|
||||
"OfficeGroup": "Marketing",
|
||||
utils.OriginID: "TestSSv1It",
|
||||
utils.RequestType: utils.META_PREPAID,
|
||||
utils.SetupTime: "2018-01-07T17:00:00Z",
|
||||
utils.AnswerTime: "2018-01-07T17:00:10Z",
|
||||
utils.Usage: 300000000000.0,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// eAcntVal = 9.2495
|
||||
// if err := sSApierRpc.Call("ApierV2.GetAccount", attrs, &acnt); err != nil {
|
||||
// t.Error(err)
|
||||
// } else if acnt.BalanceMap[utils.MONETARY].GetTotalValue() != eAcntVal {
|
||||
// t.Errorf("Expected: %f, received: %f", eAcntVal, acnt.BalanceMap[utils.MONETARY].GetTotalValue())
|
||||
// }
|
||||
// rplyt := ""
|
||||
// if err := sSv1BiRpc.Call(utils.SessionSv1ForceDisconnect,
|
||||
// map[string]string{utils.OriginID: "TestSSv1It"}, &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)
|
||||
// }
|
||||
// if err := sSApierRpc.Call("ApierV2.GetAccount", attrs, &acnt); err != nil {
|
||||
// t.Error(err)
|
||||
// } else if acnt.BalanceMap[utils.MONETARY].GetTotalValue() != eAcntVal { // no monetary change bacause the sessin was terminated
|
||||
// t.Errorf("Expected: %f, received: %f", eAcntVal, acnt.BalanceMap[utils.MONETARY].GetTotalValue())
|
||||
// }
|
||||
// time.Sleep(100 * time.Millisecond)
|
||||
// var cdrs []*engine.CDR
|
||||
// argsCDR := utils.RPCCDRsFilter{RunIDs: []string{"CustomerCharges"}, OriginIDs: []string{"TestSSv1It"}}
|
||||
// if err := sSApierRpc.Call(utils.CdrsV1GetCDRs, argsCDR, &cdrs); err != nil {
|
||||
// t.Error("Unexpected error: ", err.Error())
|
||||
// } else if len(cdrs) != 1 {
|
||||
// t.Error("Unexpected number of CDRs returned: ", len(cdrs), "\n", utils.ToJSON(cdrs))
|
||||
// } else {
|
||||
// if cdrs[0].Cost != 0.099 {
|
||||
// t.Errorf("Unexpected cost for CDR: %f", cdrs[0].Cost)
|
||||
// }
|
||||
// }
|
||||
// argsCDR = utils.RPCCDRsFilter{RunIDs: []string{"SupplierCharges"},
|
||||
// OriginIDs: []string{"TestSSv1It"}}
|
||||
// if err := sSApierRpc.Call(utils.CdrsV1GetCDRs, argsCDR, &cdrs); err != nil {
|
||||
// t.Error("Unexpected error: ", err.Error())
|
||||
// } else if len(cdrs) != 1 {
|
||||
// t.Error("Unexpected number of CDRs returned: ", len(cdrs))
|
||||
// } else {
|
||||
// if cdrs[0].Cost != 0.051 {
|
||||
// t.Errorf("Unexpected cost for CDR: %f", cdrs[0].Cost)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
if !reflect.DeepEqual(eAttrs, rply.Attributes) {
|
||||
t.Errorf("expecting: %+v, received: %+v",
|
||||
utils.ToJSON(eAttrs), utils.ToJSON(rply.Attributes))
|
||||
}
|
||||
if *rply.MaxUsage != reqUsage {
|
||||
t.Errorf("Unexpected MaxUsage: %v", rply.MaxUsage)
|
||||
}
|
||||
|
||||
// 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()))
|
||||
// }
|
||||
if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, nil, &aSessions); err != nil {
|
||||
t.Error(err)
|
||||
} else if len(aSessions) != 2 {
|
||||
t.Errorf("wrong active ssesions: %s", utils.ToJSON(aSessions))
|
||||
}
|
||||
|
||||
// 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 != time.Duration(0*time.Second) {
|
||||
// t.Errorf("Unexpected MaxUsage: %v", rply1.MaxUsage)
|
||||
// }
|
||||
eAcntVal = 9.2495
|
||||
if err := sSApierRpc.Call("ApierV2.GetAccount", attrs, &acnt); err != nil {
|
||||
t.Error(err)
|
||||
} else if acnt.BalanceMap[utils.MONETARY].GetTotalValue() != eAcntVal {
|
||||
t.Errorf("Expected: %f, received: %f", eAcntVal, acnt.BalanceMap[utils.MONETARY].GetTotalValue())
|
||||
}
|
||||
|
||||
// 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()))
|
||||
// }
|
||||
var rplyt string
|
||||
if err := sSv1BiRpc.Call(utils.SessionSv1ForceDisconnect,
|
||||
map[string]string{utils.OriginID: "TestSSv1It"}, &rplyt); err != nil {
|
||||
t.Error(err)
|
||||
} else if rplyt != utils.OK {
|
||||
t.Errorf("Unexpected reply: %s", rplyt)
|
||||
}
|
||||
|
||||
// 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 ||
|
||||
err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Errorf("Error: %v with len(asessions)=%v and sessions : %+v", err, len(aSessions), utils.ToJSON(aSessions))
|
||||
}
|
||||
if err := sSApierRpc.Call("ApierV2.GetAccount", attrs, &acnt); err != nil {
|
||||
t.Error(err)
|
||||
} else if acnt.BalanceMap[utils.MONETARY].GetTotalValue() != eAcntVal { // no monetary change bacause the sessin was terminated
|
||||
t.Errorf("Expected: %f, received: %f", eAcntVal, acnt.BalanceMap[utils.MONETARY].GetTotalValue())
|
||||
}
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
var cdrs []*engine.CDR
|
||||
argsCDR := utils.RPCCDRsFilter{RunIDs: []string{"CustomerCharges"}, OriginIDs: []string{"TestSSv1It"}}
|
||||
if err := sSApierRpc.Call(utils.CdrsV1GetCDRs, argsCDR, &cdrs); err != nil {
|
||||
t.Error("Unexpected error: ", err.Error())
|
||||
} else if len(cdrs) != 1 {
|
||||
t.Error("Unexpected number of CDRs returned: ", len(cdrs), "\n", utils.ToJSON(cdrs))
|
||||
} else {
|
||||
if cdrs[0].Cost != 0.099 {
|
||||
t.Errorf("Unexpected cost for CDR: %f", cdrs[0].Cost)
|
||||
}
|
||||
}
|
||||
argsCDR = utils.RPCCDRsFilter{RunIDs: []string{"SupplierCharges"},
|
||||
OriginIDs: []string{"TestSSv1It"}}
|
||||
if err := sSApierRpc.Call(utils.CdrsV1GetCDRs, argsCDR, &cdrs); err != nil {
|
||||
t.Error("Unexpected error: ", err.Error())
|
||||
} else if len(cdrs) != 1 {
|
||||
t.Error("Unexpected number of CDRs returned: ", len(cdrs))
|
||||
} else {
|
||||
if cdrs[0].Cost != 0.051 {
|
||||
t.Errorf("Unexpected cost for CDR: %f", cdrs[0].Cost)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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))
|
||||
// }
|
||||
// var rplyt string
|
||||
// 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 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 != time.Duration(0*time.Second) {
|
||||
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))
|
||||
}
|
||||
|
||||
var rplyt string
|
||||
if err := sSv1BiRpc.Call(utils.SessionSv1ForceDisconnect,
|
||||
nil, &rplyt); err != nil {
|
||||
t.Error(err)
|
||||
} else if rplyt != utils.OK {
|
||||
t.Errorf("Unexpected reply: %s", rplyt)
|
||||
}
|
||||
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
|
||||
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
|
||||
|
||||
@@ -81,7 +81,7 @@ func TestSessionsBiRPCStartEngine(t *testing.T) {
|
||||
|
||||
// Connect rpc client to rater
|
||||
func TestSessionsBiRPCApierRpcConn(t *testing.T) {
|
||||
clntHandlers := map[string]interface{}{"SessionSv1.DisconnectSession": handleDisconnectSession}
|
||||
clntHandlers := map[string]interface{}{utils.SessionSv1DisconnectSession: handleDisconnectSession}
|
||||
dummyClnt, err := utils.NewBiJSONrpcClient(sessionsBiRPCCfg.SessionSCfg().ListenBijson,
|
||||
clntHandlers)
|
||||
if err != nil { // First attempt is to make sure multiple clients are supported
|
||||
Reference in New Issue
Block a user