mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Finish initegration test for new session update
This commit is contained in:
committed by
Dan Christian Bogos
parent
32363d7913
commit
05cf7db8d5
@@ -61,7 +61,6 @@ func NewDiameterAgent(cgrCfg *config.CGRConfig, filterS *engine.FilterS,
|
||||
procsr.ReplyFields = tpls
|
||||
}
|
||||
}
|
||||
//da.sS.SetClientConn(da) // pass the connection to sessionS back so we can receive the disconnects
|
||||
return da, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -90,6 +90,21 @@ func TestRAitTPFromFolder(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups
|
||||
|
||||
//add a default charger
|
||||
chargerProfile := &engine.ChargerProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "Default",
|
||||
RunID: "*default",
|
||||
AttributeIDs: []string{"*none"},
|
||||
Weight: 20,
|
||||
}
|
||||
var result string
|
||||
if err := raRPC.Call("ApierV1.SetChargerProfile", chargerProfile, &result); err != nil {
|
||||
t.Error(err)
|
||||
} else if result != utils.OK {
|
||||
t.Error("Unexpected reply returned", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRAitAuth(t *testing.T) {
|
||||
@@ -260,7 +275,7 @@ func TestRAitAcctStop(t *testing.T) {
|
||||
}
|
||||
// Make sure the sessin was disconnected from SMG
|
||||
var aSessions []*sessions.ActiveSession
|
||||
if err := raRPC.Call("SMGenericV1.GetActiveSessions",
|
||||
if err := raRPC.Call(utils.SessionSv1GetActiveSessions,
|
||||
map[string]string{utils.RunID: utils.META_DEFAULT, utils.OriginID: "e4921177ab0e3586c37f6a185864b71a@0:0:0:0:0:0:0:0-51585361-75c2f57b"},
|
||||
&aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Error(err)
|
||||
|
||||
@@ -835,7 +835,7 @@ func TestSSv1ItDynamicDebit(t *testing.T) {
|
||||
args1, &rply1); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
} else if *rply1.MaxUsage != time.Duration(0*time.Second) {
|
||||
} else if *rply1.MaxUsage != time.Duration(-1) {
|
||||
t.Errorf("Unexpected MaxUsage: %v", rply1.MaxUsage)
|
||||
}
|
||||
|
||||
|
||||
@@ -378,6 +378,14 @@ func startDiameterAgent(internalSsChan chan rpcclient.RpcClientConnection,
|
||||
}
|
||||
if sSInternal { // bidirectional client backwards connection
|
||||
sS.(*utils.BiRPCInternalClient).SetClientConn(da)
|
||||
var rply string
|
||||
if err := sS.Call(utils.SessionSv1RegisterInternalBiJSONConn,
|
||||
utils.EmptyString, &rply); err != nil {
|
||||
utils.Logger.Crit(fmt.Sprintf("<%s> Could not connect to %s: %s",
|
||||
utils.DiameterAgent, utils.SessionS, err.Error()))
|
||||
exitChan <- true
|
||||
return
|
||||
}
|
||||
}
|
||||
if err = da.ListenAndServe(); err != nil {
|
||||
utils.Logger.Err(fmt.Sprintf("<DiameterAgent> error: %s!", err))
|
||||
|
||||
@@ -87,12 +87,15 @@
|
||||
"flags": ["*auth", "*accounts"],
|
||||
"continue_on_success": false,
|
||||
"request_fields":[
|
||||
{"tag": "Category", "field_id": "Category", "type": "*constant", "value": "call"},
|
||||
{"tag": "RequestType", "field_id": "RequestType", "type": "*constant",
|
||||
"value": "*prepaid", "mandatory": true},
|
||||
{"tag": "OriginID", "field_id": "OriginID", "type": "*composed",
|
||||
"value": "~*req.Acct-Session-Id;-;~*req.Sip-From-Tag", "mandatory": true},
|
||||
{"tag": "Account", "field_id": "Account", "type": "*composed",
|
||||
"value": "~*req.User-Name", "mandatory": true},
|
||||
{"tag": "Subject", "field_id": "Subject", "type": "*variable",
|
||||
"value": "~*req.User-Name", "mandatory": true},
|
||||
{"tag": "Destination", "field_id": "Destination", "type": "*composed",
|
||||
"value": "~*req.Called-Station-Id", "mandatory": true},
|
||||
{"tag": "SetupTime", "field_id": "SetupTime", "type": "*composed",
|
||||
@@ -111,6 +114,7 @@
|
||||
"flags": ["*initiate", "*attributes", "*resources", "*accounts"],
|
||||
"continue_on_success": false,
|
||||
"request_fields":[
|
||||
{"tag": "Category", "field_id": "Category", "type": "*constant", "value": "call"},
|
||||
{"tag": "RequestType", "field_id": "RequestType", "type": "*constant",
|
||||
"value": "*prepaid", "mandatory": true},
|
||||
{"tag": "OriginID", "field_id": "OriginID", "type": "*composed",
|
||||
@@ -119,6 +123,8 @@
|
||||
"value": "~*req.NAS-IP-Address", "mandatory": true},
|
||||
{"tag": "Account", "field_id": "Account", "type": "*composed",
|
||||
"value": "~*req.User-Name", "mandatory": true},
|
||||
{"tag": "Subject", "field_id": "Subject", "type": "*variable",
|
||||
"value": "~*req.User-Name", "mandatory": true},
|
||||
{"tag": "Destination", "field_id": "Destination", "type": "*composed",
|
||||
"value": "~*req.Called-Station-Id", "mandatory": true},
|
||||
{"tag": "SetupTime", "field_id": "SetupTime", "type": "*composed",
|
||||
@@ -134,6 +140,7 @@
|
||||
"flags": ["*terminate", "*resources", "*accounts", "*cdrs"],
|
||||
"continue_on_success": false,
|
||||
"request_fields":[
|
||||
{"tag": "Category", "field_id": "Category", "type": "*constant", "value": "call"},
|
||||
{"tag": "RequestType", "field_id": "RequestType", "type": "*constant",
|
||||
"value": "*prepaid", "mandatory": true},
|
||||
{"tag": "OriginID", "field_id": "OriginID", "type": "*composed",
|
||||
@@ -142,6 +149,8 @@
|
||||
"value": "~*req.NAS-IP-Address", "mandatory": true},
|
||||
{"tag": "Account", "field_id": "Account", "type": "*composed",
|
||||
"value": "~*req.User-Name", "mandatory": true},
|
||||
{"tag": "Subject", "field_id": "Subject", "type": "*variable",
|
||||
"value": "~*req.User-Name", "mandatory": true},
|
||||
{"tag": "Destination", "field_id": "Destination", "type": "*composed",
|
||||
"value": "~*req.Called-Station-Id", "mandatory": true},
|
||||
{"tag": "SetupTime", "field_id": "SetupTime", "type": "*composed",
|
||||
|
||||
@@ -442,7 +442,9 @@ func (sS *SessionS) debitSession(s *Session, sRunIdx int, dur time.Duration,
|
||||
s.Unlock()
|
||||
return
|
||||
}
|
||||
|
||||
sr := s.SRuns[sRunIdx]
|
||||
|
||||
rDur := sr.debitReserve(dur, lastUsed) // debit out of reserve, rDur is still to be debited
|
||||
if rDur == time.Duration(0) {
|
||||
s.Unlock()
|
||||
@@ -1164,6 +1166,7 @@ func (sS *SessionS) initSession(tnt string, evStart *engine.SafEvent, clntConnID
|
||||
if dbtItval != 0 &&
|
||||
sr.Event.GetStringIgnoreErrors(utils.RequestType) == utils.META_PREPAID {
|
||||
go sS.debitLoopSession(s, i, dbtItval)
|
||||
time.Sleep(1)
|
||||
}
|
||||
}
|
||||
sS.registerSession(s, false) // make the session available to the rest of the system
|
||||
@@ -1202,7 +1205,6 @@ func (sS *SessionS) updateSession(s *Session, updtEv engine.MapEvent) (maxUsage
|
||||
var maxUsageSet bool // so we know if we have set the 0 on purpose
|
||||
prepaidReqs := []string{utils.META_PREPAID, utils.META_PSEUDOPREPAID}
|
||||
for i, sr := range s.SRuns {
|
||||
|
||||
var rplyMaxUsage time.Duration
|
||||
if !utils.IsSliceMember(prepaidReqs,
|
||||
sr.Event.GetStringIgnoreErrors(utils.RequestType)) {
|
||||
@@ -1864,10 +1866,14 @@ func (sS *SessionS) BiRPCv1InitiateSession(clnt rpcclient.RpcClientConnection,
|
||||
if err != nil {
|
||||
return utils.NewErrRALs(err)
|
||||
}
|
||||
if maxUsage, err := sS.updateSession(s, nil); err != nil {
|
||||
return utils.NewErrRALs(err)
|
||||
if dbtItvl > 0 { //active debit
|
||||
rply.MaxUsage = utils.DurationPointer(time.Duration(-1))
|
||||
} else {
|
||||
rply.MaxUsage = &maxUsage
|
||||
if maxUsage, err := sS.updateSession(s, nil); err != nil {
|
||||
return utils.NewErrRALs(err)
|
||||
} else {
|
||||
rply.MaxUsage = &maxUsage
|
||||
}
|
||||
}
|
||||
}
|
||||
if args.ProcessThresholds {
|
||||
|
||||
@@ -147,7 +147,6 @@ func TestSessionsBiRPCSessionAutomaticDisconnects(t *testing.T) {
|
||||
acnt.BalanceMap[utils.VOICE].GetTotalValue())
|
||||
}
|
||||
|
||||
usage := time.Duration(10 * time.Millisecond)
|
||||
initArgs := &V1InitSessionArgs{
|
||||
InitSession: true,
|
||||
CGREvent: utils.CGREvent{
|
||||
@@ -175,9 +174,9 @@ func TestSessionsBiRPCSessionAutomaticDisconnects(t *testing.T) {
|
||||
initArgs, &initRpl); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if *initRpl.MaxUsage != usage {
|
||||
t.Errorf("Expecting : %+v, received: %+v", usage, *initRpl.MaxUsage)
|
||||
expMaxUsage := time.Duration(-1)
|
||||
if *initRpl.MaxUsage != expMaxUsage {
|
||||
t.Errorf("Expecting : %+v, received: %+v", expMaxUsage, *initRpl.MaxUsage)
|
||||
}
|
||||
|
||||
// Make sure we are receiving a disconnect event
|
||||
@@ -271,7 +270,6 @@ func TestSessionsBiRPCSessionOriginatorTerminate(t *testing.T) {
|
||||
t.Errorf("Expecting: %f, received: %f", eAcntVal, acnt.BalanceMap[utils.VOICE].GetTotalValue())
|
||||
}
|
||||
|
||||
usage := time.Duration(200 * time.Millisecond)
|
||||
initArgs := &V1InitSessionArgs{
|
||||
InitSession: true,
|
||||
CGREvent: utils.CGREvent{
|
||||
@@ -300,8 +298,9 @@ func TestSessionsBiRPCSessionOriginatorTerminate(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if *initRpl.MaxUsage != usage {
|
||||
t.Errorf("Expecting : %+v, received: %+v", usage, *initRpl.MaxUsage)
|
||||
expMaxUsage := time.Duration(-1)
|
||||
if *initRpl.MaxUsage != expMaxUsage {
|
||||
t.Errorf("Expecting : %+v, received: %+v", expMaxUsage, *initRpl.MaxUsage)
|
||||
}
|
||||
|
||||
time.Sleep(time.Duration(10 * time.Millisecond)) // Give time for debits to occur
|
||||
|
||||
@@ -199,7 +199,7 @@ func TestSessionsItUpdateUnexist(t *testing.T) {
|
||||
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
|
||||
eAcntVal = 8.283100
|
||||
eAcntVal = 8.099800
|
||||
if err := sItRPC.Call("ApierV2.GetAccount", attrs, &acnt); err != nil {
|
||||
t.Error(err)
|
||||
} else if acnt.BalanceMap[utils.MONETARY].GetTotalValue() != eAcntVal {
|
||||
|
||||
Reference in New Issue
Block a user