Updated call tests

This commit is contained in:
Tripon Alexandru-Ionut
2019-06-11 17:33:43 +03:00
committed by Dan Christian Bogos
parent 8c8238b444
commit 5e365752b0
6 changed files with 73 additions and 44 deletions

View File

@@ -1,9 +1,18 @@
#! /usr/bin/env sh #! /usr/bin/env sh
# ./local_test.sh # ./local_test.sh
lcl=$? # lcl=$?
echo 'go test github.com/cgrates/cgrates/general_tests -tags=call' echo 'go test github.com/cgrates/cgrates/general_tests -tags=call -run=TestFreeswitchCalls'
go test github.com/cgrates/cgrates/general_tests -tags=call -timeout=10h go test github.com/cgrates/cgrates/general_tests -tags=call -run=TestFreeswitchCalls
gnr=$? gnr1=$?
echo 'go test github.com/cgrates/cgrates/general_tests -tags=call -run=TestKamailioCalls'
go test github.com/cgrates/cgrates/general_tests -tags=call -run=TestKamailioCalls
gnr2=$?
echo 'go test github.com/cgrates/cgrates/general_tests -tags=call -run=TestOpensipsCalls'
go test github.com/cgrates/cgrates/general_tests -tags=call -run=TestOpensipsCalls
gnr3=$?
echo 'go test github.com/cgrates/cgrates/general_tests -tags=call -run=TestAsteriskCalls'
go test github.com/cgrates/cgrates/general_tests -tags=call -run=TestAsteriskCalls
gnr4=$?
exit $gen && $gnr exit $gnr1 && $gnr2 && $gnr3 && $gnr4

View File

@@ -43,6 +43,9 @@
"stats_conns": [ "stats_conns": [
{"address": "127.0.0.1:2012", "transport": "*json"}, {"address": "127.0.0.1:2012", "transport": "*json"},
], ],
"chargers_conns": [
{"address": "*internal"}
],
"sessions_cost_retries": 5, "sessions_cost_retries": 5,
}, },
@@ -78,6 +81,9 @@
"thresholds_conns": [ "thresholds_conns": [
{"address": "127.0.0.1:2012", "transport": "*json"}, {"address": "127.0.0.1:2012", "transport": "*json"},
], ],
"chargers_conns": [
{"address": "*internal"}
],
"store_session_costs": true, "store_session_costs": true,
"debit_interval": "5s", "debit_interval": "5s",
"channel_sync_interval":"7s", "channel_sync_interval":"7s",

View File

@@ -83,7 +83,7 @@
], ],
"store_session_costs": true, "store_session_costs": true,
"debit_interval": "5s", "debit_interval": "5s",
"channel_sync_interval":"5m", "channel_sync_interval":"7s", // default: "5m" for test please use "7s"
}, },

View File

@@ -65,8 +65,11 @@ modparam("mi_fifo", "fifo_name", "/tmp/opensips_fifo")
modparam("mi_fifo", "fifo_mode", 0666) modparam("mi_fifo", "fifo_mode", 0666)
#### URI module #### URI module
loadmodule "uri.so" # no need to load the module only to set varible to zero
modparam("uri", "use_uri_table", 0) # as default it's value is already 0
# https://opensips.org/html/docs/modules/3.0.x/uri.html#param_use_uri_table
#loadmodule "uri.so"
#modparam("uri", "use_uri_table", 0)
#### USeR LOCation module #### USeR LOCation module
loadmodule "usrloc.so" loadmodule "usrloc.so"
@@ -98,8 +101,8 @@ modparam("cgrates", "cgrates_engine", "127.0.0.1:2014")
route{ route{
if (!mf_process_maxfwd_header("10")) { if (!mf_process_maxfwd_header(10)) {
send_reply("483","Too Many Hops"); send_reply(483,"Too Many Hops");
exit; exit;
} }
@@ -116,7 +119,7 @@ route{
if ( !loose_route() ) { if ( !loose_route() ) {
# we do record-routing for all our traffic, so we should not # we do record-routing for all our traffic, so we should not
# receive any sequential requests without Route hdr. # receive any sequential requests without Route hdr.
send_reply("404","Not here"); send_reply(404,"Not here");
exit; exit;
} }
@@ -149,7 +152,7 @@ route{
# if caller is not local, then called number must be local # if caller is not local, then called number must be local
if (!is_myself("$rd")) { if (!is_myself("$rd")) {
send_reply("403","Relay Forbidden"); send_reply(403,"Relay Forbidden");
exit; exit;
} }
} }
@@ -161,7 +164,7 @@ route{
xlog("L_ERR", xlog("L_ERR",
"Attempt to route with preloaded Route's [$fu/$tu/$ru/$ci]"); "Attempt to route with preloaded Route's [$fu/$tu/$ru/$ci]");
if (!is_method("ACK")) if (!is_method("ACK"))
send_reply("403","Preload Route denied"); send_reply(403,"Preload Route denied");
exit; exit;
} }
@@ -178,7 +181,7 @@ route{
# requests for my domain # requests for my domain
if (is_method("PUBLISH|SUBSCRIBE")) { if (is_method("PUBLISH|SUBSCRIBE")) {
send_reply("503", "Service Unavailable"); send_reply(503, "Service Unavailable");
exit; exit;
} }
@@ -192,13 +195,13 @@ route{
if ($rU==NULL) { if ($rU==NULL) {
# request with no Username in RURI # request with no Username in RURI
send_reply("484","Address Incomplete"); send_reply(484,"Address Incomplete");
exit; exit;
} }
# do lookup with method filtering # do lookup with method filtering
if (!lookup("location","m")) { if (!lookup("location","m")) {
t_reply("404", "Not Found"); t_reply(404, "Not Found");
exit; exit;
} }
@@ -207,6 +210,8 @@ route{
$cgr_opt(GetAttributes) = 1; $cgr_opt(GetAttributes) = 1;
$cgr_opt(GetSuppliers) = 1; $cgr_opt(GetSuppliers) = 1;
$cgr_opt(AuthorizeResources) = 1; $cgr_opt(AuthorizeResources) = 1;
$cgr_opt(AllocateResources) = 1;
$cgr_opt(ReleaseResources) = 1;
$cgr_opt(ProcessThresholds) = 1; $cgr_opt(ProcessThresholds) = 1;
$cgr_opt(ProcessStatQueues) = 1; $cgr_opt(ProcessStatQueues) = 1;
$cgr(RequestType) = "*prepaid"; $cgr(RequestType) = "*prepaid";
@@ -214,7 +219,7 @@ route{
$cgr(Source) = "OpenSIPS"; $cgr(Source) = "OpenSIPS";
if (!async(cgrates_auth("$fU", "$rU"), resume_cgr_auth)) { if (!async(cgrates_auth("$fU", "$rU"), resume_cgr_auth)) {
sl_send_reply("503", "Service Unavailable"); sl_send_reply(503, "Service Unavailable");
exit; exit;
} }
} }
@@ -222,7 +227,7 @@ route{
route [resume_cgr_auth] { route [resume_cgr_auth] {
if ($rc == 0) { if ($rc == 0) {
xlog("Call not authorized: code=$cgrret!\n"); xlog("Call not authorized: code=$cgrret!\n");
send_reply("403", "Forbidden"); send_reply(403, "Forbidden");
exit; exit;
} }
$var(idx) = 0; $var(idx) = 0;
@@ -245,7 +250,7 @@ route[relay] {
} }
if (!t_relay()) { if (!t_relay()) {
send_reply("500","Internal Error"); send_reply(500,"Internal Error");
} }
exit; exit;
} }

View File

@@ -421,7 +421,7 @@ func testCallCall1002To1001(t *testing.T) {
func testCallCall1001To1003(t *testing.T) { func testCallCall1001To1003(t *testing.T) {
if err := engine.PjsuaCallUri( if err := engine.PjsuaCallUri(
&engine.PjsuaAccount{Id: "sip:1001@127.0.0.1", Username: "1001", Password: "CGRateS.org", Realm: "*"}, &engine.PjsuaAccount{Id: "sip:1001@127.0.0.1", Username: "1001", Password: "CGRateS.org", Realm: "*"},
"sip:1003@127.0.0.1", "sip:127.0.0.1:5080", time.Duration(60)*time.Second, 5073); err != nil { "sip:1003@127.0.0.1", "sip:127.0.0.1:5080", 60*time.Second, 5073); err != nil {
t.Fatal(err) t.Fatal(err)
} }
} }
@@ -430,7 +430,7 @@ func testCallCall1001To1003(t *testing.T) {
func testCallCall1003To1001(t *testing.T) { func testCallCall1003To1001(t *testing.T) {
if err := engine.PjsuaCallUri( if err := engine.PjsuaCallUri(
&engine.PjsuaAccount{Id: "sip:1003@127.0.0.1", Username: "1003", Password: "CGRateS.org", Realm: "*"}, &engine.PjsuaAccount{Id: "sip:1003@127.0.0.1", Username: "1003", Password: "CGRateS.org", Realm: "*"},
"sip:1001@127.0.0.1", "sip:127.0.0.1:5080", time.Duration(20)*time.Second, 5074); err != nil { "sip:1001@127.0.0.1", "sip:127.0.0.1:5080", 20*time.Second, 5074); err != nil {
t.Fatal(err) t.Fatal(err)
} }
// after this call from 1001 to 1003 and call from 1003 to 1001 should be done // after this call from 1001 to 1003 and call from 1003 to 1001 should be done
@@ -441,7 +441,7 @@ func testCallCall1003To1001SecondTime(t *testing.T) {
time.Sleep(22 * time.Second) time.Sleep(22 * time.Second)
if err := engine.PjsuaCallUri( if err := engine.PjsuaCallUri(
&engine.PjsuaAccount{Id: "sip:1003@127.0.0.1", Username: "1003", Password: "CGRateS.org", Realm: "*"}, &engine.PjsuaAccount{Id: "sip:1003@127.0.0.1", Username: "1003", Password: "CGRateS.org", Realm: "*"},
"sip:1001@127.0.0.1", "sip:127.0.0.1:5080", time.Duration(15)*time.Second, 5075); err != nil { "sip:1001@127.0.0.1", "sip:127.0.0.1:5080", 15*time.Second, 5075); err != nil {
t.Fatal(err) t.Fatal(err)
} }
time.Sleep(time.Second) time.Sleep(time.Second)
@@ -757,8 +757,8 @@ func testCallSyncSessions(t *testing.T) {
// activeSessions shouldn't be active // activeSessions shouldn't be active
if err := tutorialCallsRpc.Call(utils.SessionSv1GetActiveSessions, if err := tutorialCallsRpc.Call(utils.SessionSv1GetActiveSessions,
&map[string]string{}, &reply); err != nil && err.Error() != utils.ErrNotFound.Error() { &map[string]string{}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Error("Got error on SessionSv1.GetActiveSessions: ", err) t.Errorf("Got error on SessionSv1.GetActiveSessions: %v and reply: %s", err, utils.ToJSON(reply))
} }
var sourceForCDR string var sourceForCDR string
@@ -773,15 +773,22 @@ func testCallSyncSessions(t *testing.T) {
case utils.Asterisk: case utils.Asterisk:
sourceForCDR = utils.AsteriskAgent sourceForCDR = utils.AsteriskAgent
numberOfCDR = 3 numberOfCDR = 3
case utils.Opensips:
sourceForCDR = utils.Opensips
numberOfCDR = 3
} }
// verify cdr // verify cdr
var rplCdrs []*engine.ExternalCDR var rplCdrs []*engine.ExternalCDR
req := utils.RPCCDRsFilter{Sources: []string{sourceForCDR}, MaxUsage: "20s", req := utils.RPCCDRsFilter{
RunIDs: []string{utils.META_DEFAULT}, Accounts: []string{"1001"}} Sources: []string{sourceForCDR},
MaxUsage: "20s",
RunIDs: []string{utils.META_DEFAULT},
Accounts: []string{"1001"},
}
if err := tutorialCallsRpc.Call(utils.ApierV2GetCDRs, req, &rplCdrs); err != nil { if err := tutorialCallsRpc.Call(utils.ApierV2GetCDRs, req, &rplCdrs); err != nil {
t.Error("Unexpected error: ", err.Error()) t.Error("Unexpected error: ", err.Error())
} else if len(rplCdrs) != numberOfCDR { // cdr from sync session + cdr from before } else if len(rplCdrs) != numberOfCDR { // cdr from sync session + cdr from before
t.Fatal("Unexpected number of CDRs returned: ", len(rplCdrs)) t.Fatal("Unexpected number of CDRs returned: ", len(rplCdrs), utils.ToJSON(rplCdrs))
} else if time1, err := utils.ParseDurationWithSecs(rplCdrs[0].Usage); err != nil { } else if time1, err := utils.ParseDurationWithSecs(rplCdrs[0].Usage); err != nil {
t.Error(err) t.Error(err)
} else if time1 > time.Duration(15*time.Second) { } else if time1 > time.Duration(15*time.Second) {
@@ -814,7 +821,7 @@ func testCallSyncSessions(t *testing.T) {
func testCallStopPjsuaListener(t *testing.T) { func testCallStopPjsuaListener(t *testing.T) {
tutorialCallsPjSuaListener.Write([]byte("q\n")) // Close pjsua tutorialCallsPjSuaListener.Write([]byte("q\n")) // Close pjsua
time.Sleep(time.Duration(1) * time.Second) // Allow pjsua to finish it's tasks, eg un-REGISTER time.Sleep(time.Second) // Allow pjsua to finish it's tasks, eg un-REGISTER
} }
func testCallStopCgrEngine(t *testing.T) { func testCallStopCgrEngine(t *testing.T) {

View File

@@ -429,21 +429,23 @@ func (sS *SessionS) forceSTerminate(s *Session, extraDebit time.Duration, lastUs
utils.SessionS, err.Error(), s.ResourceID)) utils.SessionS, err.Error(), s.ResourceID))
} }
} }
if clntConn := sS.biJClnt(s.ClientConnID); clntConn != nil {
var rply string
if err := clntConn.conn.Call(utils.SessionSv1DisconnectSession,
utils.AttrDisconnectSession{
EventStart: s.EventStart.AsMapInterface(),
Reason: ErrForcedDisconnect.Error()},
&rply); err != nil {
if err != utils.ErrNotImplemented {
utils.Logger.Warning(
fmt.Sprintf("<%s> err: %s remotely disconnect session with id: %s",
utils.SessionS, err.Error(), s.CGRID))
}
}
}
sS.replicateSessions(s.CGRID, false, sS.sReplConns) sS.replicateSessions(s.CGRID, false, sS.sReplConns)
if clntConn := sS.biJClnt(s.ClientConnID); clntConn != nil {
go func() {
var rply string
if err := clntConn.conn.Call(utils.SessionSv1DisconnectSession,
utils.AttrDisconnectSession{
EventStart: s.EventStart.AsMapInterface(),
Reason: ErrForcedDisconnect.Error()},
&rply); err != nil {
if err != utils.ErrNotImplemented {
utils.Logger.Warning(
fmt.Sprintf("<%s> err: %s remotely disconnect session with id: %s",
utils.SessionS, err.Error(), s.CGRID))
}
}
}()
}
return return
} }
@@ -2541,8 +2543,8 @@ func (sS *SessionS) BiRPCv1ProcessCDR(clnt rpcclient.RpcClientConnection,
AttributeS: utils.BoolPointer(false), AttributeS: utils.BoolPointer(false),
ArgDispatcher: cgrEvWithArgDisp.ArgDispatcher, ArgDispatcher: cgrEvWithArgDisp.ArgDispatcher,
} }
if unratedReqs.HasField( // order additional rating for unrated request types if mp := engine.NewMapEvent(cgrEv.Event); mp.GetStringIgnoreErrors(utils.RunID) != utils.MetaRaw && // check if is *raw
engine.NewMapEvent(cgrEv.Event).GetStringIgnoreErrors(utils.RequestType)) { unratedReqs.HasField(mp.GetStringIgnoreErrors(utils.RequestType)) { // order additional rating for unrated request types
argsProc.RALs = utils.BoolPointer(true) argsProc.RALs = utils.BoolPointer(true)
} }
if err = sS.cdrS.Call(utils.CDRsV1ProcessEvent, if err = sS.cdrS.Call(utils.CDRsV1ProcessEvent,