From eafaf126973adc1d70d28c0e4005ccda54310bb4 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Tue, 19 Mar 2019 15:04:44 +0200 Subject: [PATCH] Added tests for mew *broadcast strategy --- .../dispatchers/dispatchers/cgrates.json | 1 + .../dispatchers_mongo/cgrates.json | 1 + data/tariffplans/dispatchers/Attributes.csv | 2 +- data/tariffplans/dispatchers/Dispatchers.csv | 2 + dispatchers/responder_it_test.go | 40 ++++++++++++++++++- 5 files changed, 43 insertions(+), 3 deletions(-) diff --git a/data/conf/samples/dispatchers/dispatchers/cgrates.json b/data/conf/samples/dispatchers/dispatchers/cgrates.json index 06b2237b8..3b6373fe7 100755 --- a/data/conf/samples/dispatchers/dispatchers/cgrates.json +++ b/data/conf/samples/dispatchers/dispatchers/cgrates.json @@ -8,6 +8,7 @@ "general": { "node_id": "DispatcherS1", + "log_level": 7, "reconnects": 1, }, diff --git a/data/conf/samples/dispatchers/dispatchers_mongo/cgrates.json b/data/conf/samples/dispatchers/dispatchers_mongo/cgrates.json index 382bc9b00..d4a51cc48 100644 --- a/data/conf/samples/dispatchers/dispatchers_mongo/cgrates.json +++ b/data/conf/samples/dispatchers/dispatchers_mongo/cgrates.json @@ -8,6 +8,7 @@ "general": { "node_id": "DispatcherS1", + "log_level": 7, "reconnects": 1, }, diff --git a/data/tariffplans/dispatchers/Attributes.csv b/data/tariffplans/dispatchers/Attributes.csv index f31a08661..dfaeb9334 100644 --- a/data/tariffplans/dispatchers/Attributes.csv +++ b/data/tariffplans/dispatchers/Attributes.csv @@ -8,5 +8,5 @@ cgrates.org,ATTR_API_SUP_AUTH,*auth,*string:~APIKey:sup12345,,,APIMethods,Suppli cgrates.org,ATTR_API_STAT_AUTH,*auth,*string:~APIKey:stat12345,,,APIMethods,StatSv1.Ping&StatSv1.GetStatQueuesForEvent&StatSv1.GetQueueStringMetrics&StatSv1.ProcessEvent&StatSv1.GetQueueIDs&StatSv1.GetQueueFloatMetrics,false,20 cgrates.org,ATTR_API_RES_AUTH,*auth,*string:~APIKey:res12345,,,APIMethods,ResourceSv1.Ping&ResourceSv1.GetResourcesForEvent&ResourceSv1.AuthorizeResources&ResourceSv1.AllocateResources&ResourceSv1.ReleaseResources,false,20 cgrates.org,ATTR_API_SES_AUTH,*auth,*string:~APIKey:ses12345,,,APIMethods,SessionSv1.Ping&SessionSv1.AuthorizeEventWithDigest&SessionSv1.InitiateSessionWithDigest&SessionSv1.UpdateSession&SessionSv1.TerminateSession&SessionSv1.ProcessCDR&SessionSv1.ProcessEvent&SessionSv1.GetActiveSessions&SessionSv1.GetActiveSessionsCount&SessionSv1.ForceDisconnect&SessionSv1.GetPassiveSessions&SessionSv1.GetPassiveSessionsCount&SessionSv1.SetPassiveSession&SessionSv1.ReplicateSessions,false,20 -cgrates.org,ATTR_API_RSP_AUTH,*auth,*string:~APIKey:rsp12345,,,APIMethods,Responder.Status&Responder.GetTimeout&Responder.Shutdown,false,20 +cgrates.org,ATTR_API_RSP_AUTH,*auth,*string:~APIKey:rsp12345,,,APIMethods,Responder.Status&Responder.GetTimeout&Responder.Shutdown&Responder.Ping,false,20 cgrates.org,ATTR_API_CHC_AUTH,*auth,*string:~APIKey:chc12345,,,APIMethods,CacheSv1.Ping&CacheSv1.GetCacheStats&CacheSv1.LoadCache&CacheSv1.PrecacheStatus&CacheSv1.GetItemIDs&CacheSv1.HasItem&CacheSv1.GetItemExpiryTime&CacheSv1.ReloadCache&CacheSv1.RemoveItem&CacheSv1.FlushCache&CacheSv1.Clear,false,20 diff --git a/data/tariffplans/dispatchers/Dispatchers.csv b/data/tariffplans/dispatchers/Dispatchers.csv index 66cb563e1..72b5de1e3 100644 --- a/data/tariffplans/dispatchers/Dispatchers.csv +++ b/data/tariffplans/dispatchers/Dispatchers.csv @@ -7,3 +7,5 @@ cgrates.org,EVENT2,*any,*string:~EventName:RoundRobin,,*round_robin,,ALL2,,20,fa cgrates.org,EVENT2,,,,,,ALL,,10,,, cgrates.org,EVENT3,*any,*string:~EventName:Random,,*random,,ALL2,,20,false,,20 cgrates.org,EVENT3,,,,,,ALL,,10,,, +cgrates.org,EVENT4,*any,*string:~EventName:Broadcast,,*broadcast,,ALL2,,20,false,,20 +cgrates.org,EVENT4,,,,,,ALL,,10,,, diff --git a/dispatchers/responder_it_test.go b/dispatchers/responder_it_test.go index ce8149aa1..d4592c8cf 100644 --- a/dispatchers/responder_it_test.go +++ b/dispatchers/responder_it_test.go @@ -32,6 +32,7 @@ var sTestsDspRsp = []func(t *testing.T){ testDspResponderShutdown, testDspResponderRandom, + testDspResponderBroadcast, } //Test start here @@ -83,7 +84,7 @@ func getNodeWithRoute(route string, t *testing.T) string { }, }, DispatcherResource: DispatcherResource{ - APIKey: "attr12345", + APIKey: "rsp12345", RouteID: &route, }, } @@ -97,7 +98,7 @@ func getNodeWithRoute(route string, t *testing.T) string { }, } - if err := dispEngine.RCP.Call(utils.AttributeSv1Ping, pingEv, &pingReply); err != nil { + if err := dispEngine.RCP.Call(utils.ResponderPing, pingEv, &pingReply); err != nil { t.Error(err) } else if pingReply != utils.Pong { t.Errorf("Received: %s", pingReply) @@ -147,3 +148,38 @@ func testDspResponderShutdown(t *testing.T) { allEngine.startEngine(t) allEngine2.startEngine(t) } + +func testDspResponderBroadcast(t *testing.T) { + var pingReply string + pingEv := CGREvWithApiKey{ + CGREvent: utils.CGREvent{ + Tenant: "cgrates.org", + Event: map[string]interface{}{ + utils.EVENT_NAME: "Broadcast", + }, + }, + DispatcherResource: DispatcherResource{ + APIKey: "rsp12345", + }, + } + if err := dispEngine.RCP.Call(utils.ResponderPing, pingEv, &pingReply); err != nil { + t.Error(err) + } else if pingReply != utils.Pong { + t.Errorf("Received: %s", pingReply) + } + + allEngine2.stopEngine(t) + pingReply = "" + if err := dispEngine.RCP.Call(utils.ResponderPing, pingEv, &pingReply); err == nil || + err.Error() != utils.ErrPartiallyExecuted.Error() { + t.Errorf("Expected error: %s received error: %v and reply %q", utils.ErrPartiallyExecuted.Error(), err, pingReply) + } + allEngine.stopEngine(t) + pingReply = "" + if err := dispEngine.RCP.Call(utils.ResponderPing, pingEv, &pingReply); err == nil || + err.Error() != utils.ErrNotExecuted.Error() { + t.Errorf("Expected error: %s received error: %v and reply %q", utils.ErrNotExecuted.Error(), err, pingReply) + } + allEngine.startEngine(t) + allEngine2.startEngine(t) +}