Fixed panic for ping methods in dispatchers

This commit is contained in:
porosnicuadrian
2021-03-31 18:11:17 +03:00
committed by Dan Christian Bogos
parent d58e231beb
commit fe506d48d4
29 changed files with 210 additions and 20 deletions

View File

@@ -535,7 +535,7 @@ func (dS *DispatcherResponder) Shutdown(args *utils.TenantWithArgDispatcher, rep
return dS.dS.ResponderShutdown(args, reply)
}
// Ping used to detreminate if component is active
// Ping used to determinate if component is active
func (dS *DispatcherResponder) Ping(args *utils.CGREventWithArgDispatcher, reply *string) error {
return dS.dS.ResponderPing(args, reply)
}

View File

@@ -23,11 +23,15 @@ import (
"github.com/cgrates/cgrates/utils"
)
// AttributeSv1Ping interogates AttributeS server responsible to process the event
// AttributeSv1Ping interrogates AttributeS server responsible to process the event
func (dS *DispatcherService) AttributeSv1Ping(args *utils.CGREventWithArgDispatcher,
reply *string) (err error) {
if args == nil {
if args == nil || (args.CGREvent == nil && args.ArgDispatcher == nil) {
args = utils.NewCGREventWithArgDispatcher()
} else if args.CGREvent == nil {
args.CGREvent = new(utils.CGREvent)
} else if args.ArgDispatcher == nil {
args.ArgDispatcher = new(utils.ArgDispatcher)
}
args.CGREvent.Tenant = utils.FirstNonEmpty(args.CGREvent.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {

View File

@@ -37,6 +37,7 @@ var sTestsDspAttr = []func(t *testing.T){
testDspAttrGetAttrRoundRobin,
testDspAttrPing,
testDspAttrPingEmptyCGREventWIthArgDispatcher,
testDspAttrTestMissingArgDispatcher,
testDspAttrTestMissingApiKey,
testDspAttrTestUnknownApiKey,
@@ -326,6 +327,15 @@ func testDspAttrPing(t *testing.T) {
}
}
func testDspAttrPingEmptyCGREventWIthArgDispatcher(t *testing.T) {
expected := "MANDATORY_IE_MISSING: [APIKey]"
var reply string
if err := dispEngine.RPC.Call(utils.AttributeSv1Ping,
&utils.CGREventWithArgDispatcher{}, &reply); err == nil || err.Error() != expected {
t.Errorf("Expected %+v, received %+v", expected, err)
}
}
func testDspAttrTestMissingArgDispatcher(t *testing.T) {
args := &engine.AttrArgsProcessEvent{
Context: utils.StringPointer("simpleauth"),

View File

@@ -28,8 +28,12 @@ import (
// CacheSv1Ping interogates CacheSv1 server responsible to process the event
func (dS *DispatcherService) CacheSv1Ping(args *utils.CGREventWithArgDispatcher,
reply *string) (err error) {
if args == nil {
if args == nil || (args.CGREvent == nil && args.ArgDispatcher == nil) {
args = utils.NewCGREventWithArgDispatcher()
} else if args.CGREvent == nil {
args.CGREvent = new(utils.CGREvent)
} else if args.ArgDispatcher == nil {
args.ArgDispatcher = new(utils.ArgDispatcher)
}
args.CGREvent.Tenant = utils.FirstNonEmpty(args.CGREvent.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {

View File

@@ -33,6 +33,7 @@ import (
var sTestsDspChc = []func(t *testing.T){
testDspChcPing,
testDspChcPingEmptyCGREventWIthArgDispatcher,
testDspChcLoadAfterFolder,
testDspChcPrecacheStatus,
testDspChcGetItemIDs,
@@ -95,6 +96,15 @@ func testDspChcPing(t *testing.T) {
}
}
func testDspChcPingEmptyCGREventWIthArgDispatcher(t *testing.T) {
var reply string
expected := "MANDATORY_IE_MISSING: [APIKey]"
if err := dispEngine.RPC.Call(utils.CacheSv1Ping,
&utils.CGREventWithArgDispatcher{}, &reply); err == nil || err.Error() != expected {
t.Errorf("Expected %+v, received %+v", expected, err)
}
}
func testDspChcLoadAfterFolder(t *testing.T) {
var rcvStats map[string]*ltcache.CacheStats
expStats := engine.GetDefaultEmptyCacheStats()

View File

@@ -28,8 +28,12 @@ import (
// CDRsV1Ping interogates CDRsV1 server responsible to process the event
func (dS *DispatcherService) CDRsV1Ping(args *utils.CGREventWithArgDispatcher,
reply *string) (err error) {
if args == nil {
if args == nil || (args.CGREvent == nil && args.ArgDispatcher == nil) {
args = utils.NewCGREventWithArgDispatcher()
} else if args.CGREvent == nil {
args.CGREvent = new(utils.CGREvent)
} else if args.ArgDispatcher == nil {
args.ArgDispatcher = new(utils.ArgDispatcher)
}
tnt := dS.cfg.GeneralCfg().DefaultTenant
if args.CGREvent != nil && args.CGREvent.Tenant != utils.EmptyString {

View File

@@ -31,6 +31,7 @@ import (
var (
sTestsDspCDRs = []func(t *testing.T){
testDspCDRsPing,
testDspCDRsPingEmptyCGREventWIthArgDispatcher,
testDspCDRsProcessEvent,
testDspCDRsCountCDR,
testDspCDRsGetCDR,
@@ -113,6 +114,15 @@ func testDspCDRsPing(t *testing.T) {
}
}
func testDspCDRsPingEmptyCGREventWIthArgDispatcher(t *testing.T) {
expected := "MANDATORY_IE_MISSING: [APIKey]"
var reply string
if err := dispEngine.RPC.Call(utils.CDRsV1Ping,
&utils.CGREventWithArgDispatcher{}, &reply); err == nil || err.Error() != expected {
t.Errorf("Expected %+v, received %+v", expected, err)
}
}
func testDspCDRsProcessEvent(t *testing.T) {
var reply string
args := &engine.ArgV1ProcessEvent{

View File

@@ -24,8 +24,12 @@ import (
)
func (dS *DispatcherService) ChargerSv1Ping(args *utils.CGREventWithArgDispatcher, reply *string) (err error) {
if args == nil {
if args == nil || (args.CGREvent == nil && args.ArgDispatcher == nil) {
args = utils.NewCGREventWithArgDispatcher()
} else if args.CGREvent == nil {
args.CGREvent = new(utils.CGREvent)
} else if args.ArgDispatcher == nil {
args.ArgDispatcher = new(utils.ArgDispatcher)
}
args.CGREvent.Tenant = utils.FirstNonEmpty(args.CGREvent.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {

View File

@@ -36,6 +36,7 @@ var sTestsDspCpp = []func(t *testing.T){
testDspCppGetChtgRoundRobin,
testDspCppPing,
testDspCppPingEmptyCGREventWIthArgDispatcher,
testDspCppTestAuthKey,
testDspCppTestAuthKey2,
}
@@ -185,6 +186,15 @@ func testDspCppPing(t *testing.T) {
}
}
func testDspCppPingEmptyCGREventWIthArgDispatcher(t *testing.T) {
expected := "MANDATORY_IE_MISSING: [APIKey]"
var reply string
if err := dispEngine.RPC.Call(utils.ChargerSv1Ping,
&utils.CGREventWithArgDispatcher{}, &reply); err == nil || err.Error() != expected {
t.Errorf("Expected %+v, received %+v", expected, err)
}
}
func testDspCppTestAuthKey(t *testing.T) {
args := utils.CGREventWithArgDispatcher{
CGREvent: &utils.CGREvent{

View File

@@ -27,8 +27,12 @@ import (
// GuardianSv1Ping interogates GuardianSv1 server responsible to process the event
func (dS *DispatcherService) GuardianSv1Ping(args *utils.CGREventWithArgDispatcher,
reply *string) (err error) {
if args == nil {
if args == nil || (args.CGREvent == nil && args.ArgDispatcher == nil) {
args = utils.NewCGREventWithArgDispatcher()
} else if args.CGREvent == nil {
args.CGREvent = new(utils.CGREvent)
} else if args.ArgDispatcher == nil {
args.ArgDispatcher = new(utils.ArgDispatcher)
}
args.CGREvent.Tenant = utils.FirstNonEmpty(args.CGREvent.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {

View File

@@ -30,6 +30,7 @@ import (
var sTestsDspGrd = []func(t *testing.T){
testDspGrdPing,
testDspGrdPingEmptyCGREventWIthArgDispatcher,
testDspGrdLock,
}
@@ -81,6 +82,15 @@ func testDspGrdPing(t *testing.T) {
}
}
func testDspGrdPingEmptyCGREventWIthArgDispatcher(t *testing.T) {
expected := "MANDATORY_IE_MISSING: [APIKey]"
var reply string
if err := dispEngine.RPC.Call(utils.GuardianSv1Ping,
&utils.CGREventWithArgDispatcher{}, &reply); err == nil || err.Error() != expected {
t.Errorf("Expected %+v, received %+v", expected, err)
}
}
func testDspGrdLock(t *testing.T) {
// lock
args := utils.AttrRemoteLock{

View File

@@ -23,8 +23,12 @@ import (
)
func (dS *DispatcherService) RALsV1Ping(args *utils.CGREventWithArgDispatcher, rpl *string) (err error) {
if args == nil {
if args == nil || (args.CGREvent == nil && args.ArgDispatcher == nil) {
args = utils.NewCGREventWithArgDispatcher()
} else if args.CGREvent == nil {
args.CGREvent = new(utils.CGREvent)
} else if args.ArgDispatcher == nil {
args.ArgDispatcher = new(utils.ArgDispatcher)
}
args.CGREvent.Tenant = utils.FirstNonEmpty(args.CGREvent.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {

View File

@@ -29,6 +29,7 @@ import (
var sTestsDspRALs = []func(t *testing.T){
testDspRALsPing,
testDspRALsPingEmptyCGREventWIthArgDispatcher,
testDspRALsGetRatingPlanCost,
}
@@ -80,6 +81,15 @@ func testDspRALsPing(t *testing.T) {
}
}
func testDspRALsPingEmptyCGREventWIthArgDispatcher(t *testing.T) {
var reply string
expected := "MANDATORY_IE_MISSING: [APIKey]"
if err := dispEngine.RPC.Call(utils.RALsV1Ping,
&utils.CGREventWithArgDispatcher{}, &reply); err == nil || err.Error() != expected {
t.Errorf("Expected %+v, received %+v", expected, err)
}
}
func testDspRALsGetRatingPlanCost(t *testing.T) {
arg := &utils.RatingPlanCostArg{
Destination: "1002",

View File

@@ -24,8 +24,12 @@ import (
)
func (dS *DispatcherService) ResourceSv1Ping(args *utils.CGREventWithArgDispatcher, rpl *string) (err error) {
if args == nil {
if args == nil || (args.CGREvent == nil && args.ArgDispatcher == nil) {
args = utils.NewCGREventWithArgDispatcher()
} else if args.CGREvent == nil {
args.CGREvent = new(utils.CGREvent)
} else if args.ArgDispatcher == nil {
args.ArgDispatcher = new(utils.ArgDispatcher)
}
args.CGREvent.Tenant = utils.FirstNonEmpty(args.CGREvent.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {

View File

@@ -32,6 +32,7 @@ var sTestsDspRes = []func(t *testing.T){
testDspResPingFailover,
testDspResPing,
testDspResPingEmptyCGREventWIthArgDispatcher,
testDspResTestAuthKey,
testDspResTestAuthKey2,
testDspResTestAuthKey3,
@@ -119,6 +120,15 @@ func testDspResPing(t *testing.T) {
}
}
func testDspResPingEmptyCGREventWIthArgDispatcher(t *testing.T) {
expected := "MANDATORY_IE_MISSING: [APIKey]"
var reply string
if err := dispEngine.RPC.Call(utils.ResourceSv1Ping,
&utils.CGREventWithArgDispatcher{}, &reply); err == nil || err.Error() != expected {
t.Errorf("Expected %+v, received %+v", expected, err)
}
}
func testDspResTestAuthKey(t *testing.T) {
var rs *engine.Resources
args := &utils.ArgRSv1ResourceUsage{

View File

@@ -28,8 +28,12 @@ import (
// ResponderPing interogates Responder server responsible to process the event
func (dS *DispatcherService) ResponderPing(args *utils.CGREventWithArgDispatcher,
reply *string) (err error) {
if args == nil {
if args == nil || (args.CGREvent == nil && args.ArgDispatcher == nil) {
args = utils.NewCGREventWithArgDispatcher()
} else if args.CGREvent == nil {
args.CGREvent = new(utils.CGREvent)
} else if args.ArgDispatcher == nil {
args.ArgDispatcher = new(utils.ArgDispatcher)
}
args.CGREvent.Tenant = utils.FirstNonEmpty(args.CGREvent.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {

View File

@@ -34,6 +34,7 @@ var sTestsDspRsp = []func(t *testing.T){
testDspResponderRandom,
testDspResponderBroadcast,
testDspResponderInternal,
testDspResponderPingEmptyCGREventWIthArgDispatcher,
}
//Test start here
@@ -246,3 +247,12 @@ func testDspResponderInternal(t *testing.T) {
t.Errorf("Expected: DispatcherS1 , received: %s", strRply)
}
}
func testDspResponderPingEmptyCGREventWIthArgDispatcher(t *testing.T) {
expected := "MANDATORY_IE_MISSING: [APIKey]"
var reply string
if err := dispEngine.RPC.Call(utils.ResponderPing,
&utils.CGREventWithArgDispatcher{}, &reply); err == nil || err.Error() != expected {
t.Errorf("Expected %+v, received %+v", expected, err)
}
}

View File

@@ -23,8 +23,12 @@ import (
)
func (dS *DispatcherService) SchedulerSv1Ping(args *utils.CGREventWithArgDispatcher, reply *string) (err error) {
if args == nil {
if args == nil || (args.CGREvent == nil && args.ArgDispatcher == nil) {
args = utils.NewCGREventWithArgDispatcher()
} else if args.CGREvent == nil {
args.CGREvent = new(utils.CGREvent)
} else if args.ArgDispatcher == nil {
args.ArgDispatcher = new(utils.ArgDispatcher)
}
args.CGREvent.Tenant = utils.FirstNonEmpty(args.CGREvent.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {

View File

@@ -28,10 +28,10 @@ import (
var sTestsDspSched = []func(t *testing.T){
testDspSchedPing,
testDspSchedPingEmptyCGREventWIthArgDispatcher,
}
//Test start here
func TestDspSchedulerS(t *testing.T) {
var config1, config2, config3 string
switch *dbType {
@@ -78,3 +78,12 @@ func testDspSchedPing(t *testing.T) {
t.Errorf("Received: %s", reply)
}
}
func testDspSchedPingEmptyCGREventWIthArgDispatcher(t *testing.T) {
expected := "MANDATORY_IE_MISSING: [APIKey]"
var reply string
if err := dispEngine.RPC.Call(utils.SchedulerSv1Ping,
&utils.CGREventWithArgDispatcher{}, &reply); err == nil || err.Error() != expected {
t.Errorf("Expected %+v, received %+v", expected, err)
}
}

View File

@@ -26,6 +26,13 @@ import (
)
func (dS *DispatcherService) SessionSv1Ping(args *utils.CGREventWithArgDispatcher, reply *string) (err error) {
if args == nil || (args.CGREvent == nil && args.ArgDispatcher == nil) {
args = utils.NewCGREventWithArgDispatcher()
} else if args.CGREvent == nil {
args.CGREvent = new(utils.CGREvent)
} else if args.ArgDispatcher == nil {
args.ArgDispatcher = new(utils.ArgDispatcher)
}
args.CGREvent.Tenant = utils.FirstNonEmpty(args.CGREvent.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
if args.ArgDispatcher == nil {

View File

@@ -39,6 +39,7 @@ var sTestsDspSession = []func(t *testing.T){
testDspSessionPingFailover,
testDspSessionPing,
testDspSessPingEmptyCGREventWIthArgDispatcher,
testDspSessionTestAuthKey,
testDspSessionAuthorize,
testDspSessionInit,
@@ -148,6 +149,15 @@ func testDspSessionPing(t *testing.T) {
}
}
func testDspSessPingEmptyCGREventWIthArgDispatcher(t *testing.T) {
expected := "MANDATORY_IE_MISSING: [APIKey]"
var reply string
if err := dispEngine.RPC.Call(utils.SessionSv1Ping,
&utils.CGREventWithArgDispatcher{}, &reply); err == nil || err.Error() != expected {
t.Errorf("Expected %+v, received %+v", expected, err)
}
}
func testDspSessionPingFailover(t *testing.T) {
var reply string
if err := allEngine.RPC.Call(utils.SessionSv1Ping, new(utils.CGREvent), &reply); err != nil {

View File

@@ -26,8 +26,12 @@ import (
)
func (dS *DispatcherService) StatSv1Ping(args *utils.CGREventWithArgDispatcher, reply *string) (err error) {
if args == nil {
if args == nil || (args.CGREvent == nil && args.ArgDispatcher == nil) {
args = utils.NewCGREventWithArgDispatcher()
} else if args.CGREvent == nil {
args.CGREvent = new(utils.CGREvent)
} else if args.ArgDispatcher == nil {
args.ArgDispatcher = new(utils.ArgDispatcher)
}
args.CGREvent.Tenant = utils.FirstNonEmpty(args.CGREvent.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {

View File

@@ -35,6 +35,7 @@ var sTestsDspSts = []func(t *testing.T){
testDspStsGetStatFailover,
testDspStsPing,
testDspStsPingEmptyCGREventWIthArgDispatcher,
testDspStsTestAuthKey,
testDspStsTestAuthKey2,
testDspStsTestAuthKey3,
@@ -174,6 +175,15 @@ func testDspStsPing(t *testing.T) {
}
}
func testDspStsPingEmptyCGREventWIthArgDispatcher(t *testing.T) {
expected := "MANDATORY_IE_MISSING: [APIKey]"
var reply string
if err := dispEngine.RPC.Call(utils.StatSv1Ping,
&utils.CGREventWithArgDispatcher{}, &reply); err == nil || err.Error() != expected {
t.Errorf("Expected %+v, received %+v", expected, err)
}
}
func testDspStsTestAuthKey(t *testing.T) {
var reply []string
args := engine.StatsArgsProcessEvent{

View File

@@ -24,8 +24,12 @@ import (
)
func (dS *DispatcherService) SupplierSv1Ping(args *utils.CGREventWithArgDispatcher, reply *string) (err error) {
if args == nil {
if args == nil || (args.CGREvent == nil && args.ArgDispatcher == nil) {
args = utils.NewCGREventWithArgDispatcher()
} else if args.CGREvent == nil {
args.CGREvent = new(utils.CGREvent)
} else if args.ArgDispatcher == nil {
args.ArgDispatcher = new(utils.ArgDispatcher)
}
args.CGREvent.Tenant = utils.FirstNonEmpty(args.CGREvent.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {

View File

@@ -36,6 +36,7 @@ var sTestsDspSup = []func(t *testing.T){
testDspSupGetSupRoundRobin,
testDspSupPing,
testDspSupPingEmptyCGREventWIthArgDispatcher,
testDspSupTestAuthKey,
testDspSupTestAuthKey2,
testDspSupGetSupplierForEvent,
@@ -89,6 +90,15 @@ func testDspSupPing(t *testing.T) {
}
}
func testDspSupPingEmptyCGREventWIthArgDispatcher(t *testing.T) {
expected := "MANDATORY_IE_MISSING: [APIKey]"
var reply string
if err := dispEngine.RPC.Call(utils.SupplierSv1Ping,
&utils.CGREventWithArgDispatcher{}, &reply); err == nil || err.Error() != expected {
t.Errorf("Expected %+v, received %+v", expected, err)
}
}
func testDspSupPingFailover(t *testing.T) {
var reply string
if err := allEngine.RPC.Call(utils.SupplierSv1Ping, new(utils.CGREvent), &reply); err != nil {

View File

@@ -26,8 +26,12 @@ import (
)
func (dS *DispatcherService) ThresholdSv1Ping(args *utils.CGREventWithArgDispatcher, reply *string) (err error) {
if args == nil {
if args == nil || (args.CGREvent == nil && args.ArgDispatcher == nil) {
args = utils.NewCGREventWithArgDispatcher()
} else if args.CGREvent == nil {
args.CGREvent = new(utils.CGREvent)
} else if args.ArgDispatcher == nil {
args.ArgDispatcher = new(utils.ArgDispatcher)
}
args.CGREvent.Tenant = utils.FirstNonEmpty(args.CGREvent.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
if args.ArgDispatcher == nil {

View File

@@ -35,6 +35,7 @@ var sTestsDspTh = []func(t *testing.T){
testDspThProcessEventFailover,
testDspThPing,
testDspThPingEmptyCGREventWIthArgDispatcher,
testDspThTestAuthKey,
testDspThTestAuthKey2,
testDspThTestAuthKey3,
@@ -153,6 +154,15 @@ func testDspThPing(t *testing.T) {
}
}
func testDspThPingEmptyCGREventWIthArgDispatcher(t *testing.T) {
expected := "MANDATORY_IE_MISSING: [APIKey]"
var reply string
if err := dispEngine.RPC.Call(utils.ThresholdSv1Ping,
&utils.CGREventWithArgDispatcher{}, &reply); err == nil || err.Error() != expected {
t.Errorf("Expected %+v, received %+v", expected, err)
}
}
func testDspThTestAuthKey(t *testing.T) {
var ids []string
nowTime := time.Now()

View File

@@ -224,7 +224,10 @@ type CGREvents struct {
}
func NewCGREventWithArgDispatcher() *CGREventWithArgDispatcher {
return new(CGREventWithArgDispatcher)
return &CGREventWithArgDispatcher{
CGREvent: new(CGREvent),
ArgDispatcher: new(ArgDispatcher),
}
}
type CGREventWithArgDispatcher struct {

View File

@@ -447,11 +447,14 @@ func TestCGREventConsumeArgs(t *testing.T) {
}
func TestNewCGREventWithArgDispatcher(t *testing.T) {
eOut := new(CGREventWithArgDispatcher)
rcv := NewCGREventWithArgDispatcher()
exp := &CGREventWithArgDispatcher{
CGREvent: new(CGREvent),
ArgDispatcher: new(ArgDispatcher),
}
eOut := NewCGREventWithArgDispatcher()
if !reflect.DeepEqual(eOut, rcv) {
t.Errorf("Expecting: %+v, received: %+v", eOut, rcv)
if !reflect.DeepEqual(eOut, exp) {
t.Errorf("Expecting: %+v, received: %+v", eOut, exp)
}
}