From eb8d2829b6f9c1d04c82bc04a9a0ce75abd39d46 Mon Sep 17 00:00:00 2001 From: andronache Date: Fri, 17 Sep 2021 15:53:39 +0300 Subject: [PATCH] Finished test and fix for config reload not enabling rates --- .../cfg_rld_rates_internal/cgrates.json | 29 ++++++++++ .../samples/cfg_rld_rates_mongo/cgrates.json | 32 +++++++++++ .../samples/cfg_rld_rates_mysql/cgrates.json | 29 ++++++++++ ...test.go => config_reload_rates_it_test.go} | 57 ++++--------------- 4 files changed, 100 insertions(+), 47 deletions(-) create mode 100644 data/conf/samples/cfg_rld_rates_internal/cgrates.json create mode 100644 data/conf/samples/cfg_rld_rates_mongo/cgrates.json create mode 100644 data/conf/samples/cfg_rld_rates_mysql/cgrates.json rename general_tests/{rate_config_enable_it_test.go => config_reload_rates_it_test.go} (70%) diff --git a/data/conf/samples/cfg_rld_rates_internal/cgrates.json b/data/conf/samples/cfg_rld_rates_internal/cgrates.json new file mode 100644 index 000000000..3e66332ae --- /dev/null +++ b/data/conf/samples/cfg_rld_rates_internal/cgrates.json @@ -0,0 +1,29 @@ +{ +// CGRateS Configuration file +// + + +"general": { + "log_level": 7, + "reply_timeout": "50s" +}, + + +"listen": { + "rpc_json": ":2012", + "rpc_gob": ":2013", + "http": ":2080" +}, + + +"data_db": { + "db_type": "*internal" +}, + + +"stor_db": { + "db_type": "*internal" +}, + + +} diff --git a/data/conf/samples/cfg_rld_rates_mongo/cgrates.json b/data/conf/samples/cfg_rld_rates_mongo/cgrates.json new file mode 100644 index 000000000..39804dd01 --- /dev/null +++ b/data/conf/samples/cfg_rld_rates_mongo/cgrates.json @@ -0,0 +1,32 @@ +{ +// CGRateS Configuration file + + +"general": { + "log_level": 7, + "reply_timeout": "30s", +}, + + +"listen": { + "rpc_json": ":2012", + "rpc_gob": ":2013", + "http": ":2080", +}, + + +"data_db": { + "db_type": "mongo", + "db_name": "10", + "db_port": 27017, +}, + + +"stor_db": { + "db_type": "mongo", + "db_name": "cgrates", + "db_port": 27017, +}, + + +} diff --git a/data/conf/samples/cfg_rld_rates_mysql/cgrates.json b/data/conf/samples/cfg_rld_rates_mysql/cgrates.json new file mode 100644 index 000000000..1c87919b3 --- /dev/null +++ b/data/conf/samples/cfg_rld_rates_mysql/cgrates.json @@ -0,0 +1,29 @@ +{ +// CGRateS Configuration file +// + + +"general": { + "log_level": 7, + "reply_timeout": "50s", +}, + + +"listen": { + "rpc_json": ":2012", + "rpc_gob": ":2013", + "http": ":2080", +}, + +"data_db": { // database used to store runtime data (eg: accounts, cdr stats) + "db_type": "redis", // data_db type: + "db_port": 6379, // data_db port to reach the database + "db_name": "10", // data_db database name to connect to +}, + +"stor_db": { + "db_password": "CGRateS.org", +}, + + +} diff --git a/general_tests/rate_config_enable_it_test.go b/general_tests/config_reload_rates_it_test.go similarity index 70% rename from general_tests/rate_config_enable_it_test.go rename to general_tests/config_reload_rates_it_test.go index 5f98ba929..cdb45b57d 100644 --- a/general_tests/rate_config_enable_it_test.go +++ b/general_tests/config_reload_rates_it_test.go @@ -4,17 +4,14 @@ /* Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments Copyright (C) ITsysCOM GmbH - This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along with this program. If not, see */ @@ -43,7 +40,7 @@ var ( testRateResetStorDb, testRateStartEngine, testRateRPCConn, - //testRateConfigSReloadRates, + testRateConfigSReloadRates, testRateStopCgrEngine, } ) @@ -51,11 +48,11 @@ var ( func TestRateChange(t *testing.T) { switch *dbType { case utils.MetaInternal: - testRateCfgDir = "tutinternal" + testRateCfgDir = "cfg_rld_rates_internal" case utils.MetaMySQL: - testRateCfgDir = "tutmysql" + testRateCfgDir = "cfg_rld_rates_mysql" case utils.MetaMongo: - testRateCfgDir = "tutmongo" + testRateCfgDir = "cfg_rld_rates_mongo" case utils.MetaPostgres: t.SkipNow() default: @@ -67,6 +64,7 @@ func TestRateChange(t *testing.T) { } func testRateLoadConfig(t *testing.T) { + var err error testRateCfgPath = path.Join(*dataDir, "conf", "samples", testRateCfgDir) if testRateCfg, err = config.NewCGRConfigFromPath(testRateCfgPath); err != nil { t.Error(err) @@ -94,56 +92,23 @@ func testRateStartEngine(t *testing.T) { func testRateConfigSReloadRates(t *testing.T) { var replyPingBf string - if err := testRateRPC.Call(context.Background(), utils.RateSv1CostForEvent, &utils.CGREvent{}, &replyPingBf); err != nil { + if err := testRateRPC.Call(context.Background(), utils.RateSv1CostForEvent, &utils.CGREvent{}, &replyPingBf); err == nil || err.Error() != "rpc: can't find service RateSv1.CostForEvent" { t.Error(err) - } else if replyPingBf != utils.Pong { - t.Errorf("Expected OK received: %s", replyPingBf) } - var reply string if err := testRateRPC.Call(context.Background(), utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{ Tenant: "cgrates.org", - Config: ` "rates": { - "enabled": true, - "indexed_selects": true, - "nested_fields": false, - "prefix_indexed_fields": [], - "rate_indexed_selects": true, - "rate_nested_fields": false, - "rate_prefix_indexed_fields": [ - "*req.Destination" - ], - "rate_string_indexed_fields": [], - "rate_suffix_indexed_fields": [], - "string_indexed_fields": [], - "suffix_indexed_fields": [], - "verbosity": 1000 - },`, + Config: "{\"rates\":{\"enabled\":true}}", }, &reply); err != nil { t.Error(err) } else if reply != utils.OK { t.Errorf("Expected OK received: %+v", reply) } - cfgStr := ` "rates": { - "enabled": true, - "indexed_selects": true, - "nested_fields": false, - "prefix_indexed_fields": [], - "rate_indexed_selects": true, - "rate_nested_fields": false, - "rate_prefix_indexed_fields": [ - "*req.Destination" - ], - "rate_string_indexed_fields": [], - "rate_suffix_indexed_fields": [], - "string_indexed_fields": [], - "suffix_indexed_fields": [], - "verbosity": 1000 - },` + cfgStr := "{\"rates\":{\"enabled\":true,\"indexed_selects\":true,\"nested_fields\":false,\"prefix_indexed_fields\":[],\"rate_indexed_selects\":true,\"rate_nested_fields\":false,\"rate_prefix_indexed_fields\":[],\"rate_suffix_indexed_fields\":[],\"suffix_indexed_fields\":[],\"verbosity\":1000}}" var rpl string if err := testRateRPC.Call(context.Background(), utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{ Tenant: "cgrates.org", - Sections: []string{config.StatSJSON}, + Sections: []string{config.RateSJSON}, }, &rpl); err != nil { t.Error(err) } else if cfgStr != rpl { @@ -151,10 +116,8 @@ func testRateConfigSReloadRates(t *testing.T) { } var replyPingAf string - if err := testRateRPC.Call(context.Background(), utils.StatSv1Ping, &utils.CGREvent{}, &replyPingAf); err != nil { + if err := testRateRPC.Call(context.Background(), utils.RateSv1CostForEvent, &utils.CGREvent{}, &replyPingAf); err == nil || err.Error() != "NOT_FOUND" { t.Error(err) - } else if replyPingAf != utils.Pong { - t.Errorf("Expected OK received: %s", replyPingAf) } }