diff --git a/calls_test.sh b/calls_test.sh index 746f6d779..28ac5a563 100755 --- a/calls_test.sh +++ b/calls_test.sh @@ -1,9 +1,18 @@ #! /usr/bin/env sh # ./local_test.sh -lcl=$? -echo 'go test github.com/cgrates/cgrates/general_tests -tags=call' -go test github.com/cgrates/cgrates/general_tests -tags=call -timeout=10h -gnr=$? +# lcl=$? +echo 'go test github.com/cgrates/cgrates/general_tests -tags=call -run=TestFreeswitchCalls' +go test github.com/cgrates/cgrates/general_tests -tags=call -run=TestFreeswitchCalls +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 \ No newline at end of file +exit $gnr1 && $gnr2 && $gnr3 && $gnr4 \ No newline at end of file diff --git a/data/tutorials/asterisk_ari/cgrates/etc/cgrates/cgrates.json b/data/tutorials/asterisk_ari/cgrates/etc/cgrates/cgrates.json index 415342768..6878cc3a6 100644 --- a/data/tutorials/asterisk_ari/cgrates/etc/cgrates/cgrates.json +++ b/data/tutorials/asterisk_ari/cgrates/etc/cgrates/cgrates.json @@ -43,6 +43,9 @@ "stats_conns": [ {"address": "127.0.0.1:2012", "transport": "*json"}, ], + "chargers_conns": [ + {"address": "*internal"} + ], "sessions_cost_retries": 5, }, @@ -78,6 +81,9 @@ "thresholds_conns": [ {"address": "127.0.0.1:2012", "transport": "*json"}, ], + "chargers_conns": [ + {"address": "*internal"} + ], "store_session_costs": true, "debit_interval": "5s", "channel_sync_interval":"7s", diff --git a/data/tutorials/kamevapi/cgrates/etc/cgrates/cgrates.json b/data/tutorials/kamevapi/cgrates/etc/cgrates/cgrates.json index f15bac3b7..7cb209405 100644 --- a/data/tutorials/kamevapi/cgrates/etc/cgrates/cgrates.json +++ b/data/tutorials/kamevapi/cgrates/etc/cgrates/cgrates.json @@ -83,7 +83,7 @@ ], "store_session_costs": true, "debit_interval": "5s", - "channel_sync_interval":"5m", + "channel_sync_interval":"7s", // default: "5m" for test please use "7s" }, diff --git a/data/tutorials/osips_native/opensips/etc/opensips/opensips.cfg b/data/tutorials/osips_native/opensips/etc/opensips/opensips.cfg index 739c88055..01fafb284 100644 --- a/data/tutorials/osips_native/opensips/etc/opensips/opensips.cfg +++ b/data/tutorials/osips_native/opensips/etc/opensips/opensips.cfg @@ -65,8 +65,11 @@ modparam("mi_fifo", "fifo_name", "/tmp/opensips_fifo") modparam("mi_fifo", "fifo_mode", 0666) #### URI module -loadmodule "uri.so" -modparam("uri", "use_uri_table", 0) +# no need to load the module only to set varible to zero +# 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 loadmodule "usrloc.so" @@ -98,8 +101,8 @@ modparam("cgrates", "cgrates_engine", "127.0.0.1:2014") route{ - if (!mf_process_maxfwd_header("10")) { - send_reply("483","Too Many Hops"); + if (!mf_process_maxfwd_header(10)) { + send_reply(483,"Too Many Hops"); exit; } @@ -116,7 +119,7 @@ route{ if ( !loose_route() ) { # we do record-routing for all our traffic, so we should not # receive any sequential requests without Route hdr. - send_reply("404","Not here"); + send_reply(404,"Not here"); exit; } @@ -149,7 +152,7 @@ route{ # if caller is not local, then called number must be local if (!is_myself("$rd")) { - send_reply("403","Relay Forbidden"); + send_reply(403,"Relay Forbidden"); exit; } } @@ -161,7 +164,7 @@ route{ xlog("L_ERR", "Attempt to route with preloaded Route's [$fu/$tu/$ru/$ci]"); if (!is_method("ACK")) - send_reply("403","Preload Route denied"); + send_reply(403,"Preload Route denied"); exit; } @@ -178,7 +181,7 @@ route{ # requests for my domain if (is_method("PUBLISH|SUBSCRIBE")) { - send_reply("503", "Service Unavailable"); + send_reply(503, "Service Unavailable"); exit; } @@ -192,13 +195,13 @@ route{ if ($rU==NULL) { # request with no Username in RURI - send_reply("484","Address Incomplete"); + send_reply(484,"Address Incomplete"); exit; } # do lookup with method filtering if (!lookup("location","m")) { - t_reply("404", "Not Found"); + t_reply(404, "Not Found"); exit; } @@ -207,6 +210,8 @@ route{ $cgr_opt(GetAttributes) = 1; $cgr_opt(GetSuppliers) = 1; $cgr_opt(AuthorizeResources) = 1; + $cgr_opt(AllocateResources) = 1; + $cgr_opt(ReleaseResources) = 1; $cgr_opt(ProcessThresholds) = 1; $cgr_opt(ProcessStatQueues) = 1; $cgr(RequestType) = "*prepaid"; @@ -214,7 +219,7 @@ route{ $cgr(Source) = "OpenSIPS"; if (!async(cgrates_auth("$fU", "$rU"), resume_cgr_auth)) { - sl_send_reply("503", "Service Unavailable"); + sl_send_reply(503, "Service Unavailable"); exit; } } @@ -222,7 +227,7 @@ route{ route [resume_cgr_auth] { if ($rc == 0) { xlog("Call not authorized: code=$cgrret!\n"); - send_reply("403", "Forbidden"); + send_reply(403, "Forbidden"); exit; } $var(idx) = 0; @@ -245,7 +250,7 @@ route[relay] { } if (!t_relay()) { - send_reply("500","Internal Error"); + send_reply(500,"Internal Error"); } exit; } diff --git a/general_tests/tutorial_calls_test.go b/general_tests/tutorial_calls_test.go index fc3e55907..00480f764 100755 --- a/general_tests/tutorial_calls_test.go +++ b/general_tests/tutorial_calls_test.go @@ -421,7 +421,7 @@ func testCallCall1002To1001(t *testing.T) { func testCallCall1001To1003(t *testing.T) { if err := engine.PjsuaCallUri( &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) } } @@ -430,7 +430,7 @@ func testCallCall1001To1003(t *testing.T) { func testCallCall1003To1001(t *testing.T) { if err := engine.PjsuaCallUri( &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) } // 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) if err := engine.PjsuaCallUri( &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) } time.Sleep(time.Second) @@ -757,8 +757,8 @@ func testCallSyncSessions(t *testing.T) { // activeSessions shouldn't be active if err := tutorialCallsRpc.Call(utils.SessionSv1GetActiveSessions, - &map[string]string{}, &reply); err != nil && err.Error() != utils.ErrNotFound.Error() { - t.Error("Got error on SessionSv1.GetActiveSessions: ", err) + &map[string]string{}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { + t.Errorf("Got error on SessionSv1.GetActiveSessions: %v and reply: %s", err, utils.ToJSON(reply)) } var sourceForCDR string @@ -773,15 +773,22 @@ func testCallSyncSessions(t *testing.T) { case utils.Asterisk: sourceForCDR = utils.AsteriskAgent numberOfCDR = 3 + case utils.Opensips: + sourceForCDR = utils.Opensips + numberOfCDR = 3 } // verify cdr var rplCdrs []*engine.ExternalCDR - req := utils.RPCCDRsFilter{Sources: []string{sourceForCDR}, MaxUsage: "20s", - RunIDs: []string{utils.META_DEFAULT}, Accounts: []string{"1001"}} + req := utils.RPCCDRsFilter{ + Sources: []string{sourceForCDR}, + MaxUsage: "20s", + RunIDs: []string{utils.META_DEFAULT}, + Accounts: []string{"1001"}, + } if err := tutorialCallsRpc.Call(utils.ApierV2GetCDRs, req, &rplCdrs); err != nil { t.Error("Unexpected error: ", err.Error()) } 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 { t.Error(err) } else if time1 > time.Duration(15*time.Second) { @@ -814,7 +821,7 @@ func testCallSyncSessions(t *testing.T) { func testCallStopPjsuaListener(t *testing.T) { 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) { diff --git a/sessions/sessions.go b/sessions/sessions.go index d8dd3259a..f83e5a60d 100644 --- a/sessions/sessions.go +++ b/sessions/sessions.go @@ -429,21 +429,23 @@ func (sS *SessionS) forceSTerminate(s *Session, extraDebit time.Duration, lastUs 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) + 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 } @@ -2541,8 +2543,8 @@ func (sS *SessionS) BiRPCv1ProcessCDR(clnt rpcclient.RpcClientConnection, AttributeS: utils.BoolPointer(false), ArgDispatcher: cgrEvWithArgDisp.ArgDispatcher, } - if unratedReqs.HasField( // order additional rating for unrated request types - engine.NewMapEvent(cgrEv.Event).GetStringIgnoreErrors(utils.RequestType)) { + if mp := engine.NewMapEvent(cgrEv.Event); mp.GetStringIgnoreErrors(utils.RunID) != utils.MetaRaw && // check if is *raw + unratedReqs.HasField(mp.GetStringIgnoreErrors(utils.RequestType)) { // order additional rating for unrated request types argsProc.RALs = utils.BoolPointer(true) } if err = sS.cdrS.Call(utils.CDRsV1ProcessEvent,