From 044311888d342d49845b765e95041c89859671a8 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Thu, 5 Nov 2020 14:20:23 +0200 Subject: [PATCH] Updated caps integration tests --- .../{concreqs_it_test.go => caps_it_test.go} | 22 +++++++++---------- config/config.go | 2 +- config/corescfg_test.go | 4 ++-- cores/caps.go | 3 +-- .../cgrates.json | 0 .../cgrates.json | 0 .../cgrates.json | 0 7 files changed, 15 insertions(+), 16 deletions(-) rename apier/v1/{concreqs_it_test.go => caps_it_test.go} (93%) rename data/conf/samples/{conc_reqs_busy => caps_busy}/cgrates.json (100%) rename data/conf/samples/{conc_reqs_queue => caps_queue}/cgrates.json (100%) rename data/conf/samples/{conc_reqs_queue_bench => caps_queue_bench}/cgrates.json (100%) diff --git a/apier/v1/concreqs_it_test.go b/apier/v1/caps_it_test.go similarity index 93% rename from apier/v1/concreqs_it_test.go rename to apier/v1/caps_it_test.go index 4cae6eb78..a2e2fc3c0 100644 --- a/apier/v1/concreqs_it_test.go +++ b/apier/v1/caps_it_test.go @@ -66,14 +66,14 @@ var ( //Test start here func TestCapsBusyJSON(t *testing.T) { - capsConfigDIR = "conc_reqs_busy" + capsConfigDIR = "caps_busy" for _, stest := range sTestsCaps { t.Run(capsConfigDIR, stest) } } func TestCapsQueueJSON(t *testing.T) { - capsConfigDIR = "conc_reqs_queue" + capsConfigDIR = "caps_queue" for _, stest := range sTestsCaps { t.Run(capsConfigDIR, stest) } @@ -115,7 +115,7 @@ func testCapsRPCConn(t *testing.T) { } func testCapsBusyAPIs(t *testing.T) { - if capsConfigDIR != "conc_reqs_busy" { + if capsConfigDIR != "caps_busy" { t.SkipNow() } var failedAPIs int @@ -144,7 +144,7 @@ func testCapsBusyAPIs(t *testing.T) { } func testCapsQueueAPIs(t *testing.T) { - if capsConfigDIR != "conc_reqs_queue" { + if capsConfigDIR != "caps_queue" { t.SkipNow() } wg := new(sync.WaitGroup) @@ -166,7 +166,7 @@ func testCapsQueueAPIs(t *testing.T) { } func testCapsOnHTTPBusy(t *testing.T) { - if capsConfigDIR != "conc_reqs_busy" { + if capsConfigDIR != "caps_busy" { t.SkipNow() } var fldAPIs int64 @@ -175,7 +175,7 @@ func testCapsOnHTTPBusy(t *testing.T) { for i := 0; i < 5; i++ { wg.Add(1) go func(index int) { - resp, err := http.Post("http://localhost:2080/jsonrpc", "application/json", bytes.NewBuffer([]byte(fmt.Sprintf(`{"method": "CoreSv1.Sleep", "params": [{"DurationTime":10000000}], "id":%d}`, index)))) + resp, err := http.Post("http://localhost:2080/jsonrpc", "application/json", bytes.NewBuffer([]byte(fmt.Sprintf(`{"method": "CoreSv1.Sleep", "params": [{"Duration":10000000}], "id":%d}`, index)))) if err != nil { wg.Done() t.Error(err) @@ -204,14 +204,14 @@ func testCapsOnHTTPBusy(t *testing.T) { } func testCapsOnHTTPQueue(t *testing.T) { - if capsConfigDIR != "conc_reqs_queue" { + if capsConfigDIR != "caps_queue" { t.SkipNow() } wg := new(sync.WaitGroup) for i := 0; i < 5; i++ { wg.Add(1) go func(index int) { - _, err := http.Post("http://localhost:2080/jsonrpc", "application/json", bytes.NewBuffer([]byte(fmt.Sprintf(`{"method": "CoreSv1.Sleep", "params": [{"DurationTime":10000000}], "id":%d}`, index)))) + _, err := http.Post("http://localhost:2080/jsonrpc", "application/json", bytes.NewBuffer([]byte(fmt.Sprintf(`{"method": "CoreSv1.Sleep", "params": [{"Duration":10000000}], "id":%d}`, index)))) if err != nil { wg.Done() t.Error(err) @@ -225,7 +225,7 @@ func testCapsOnHTTPQueue(t *testing.T) { } func testCapsOnBiJSONBusy(t *testing.T) { - if capsConfigDIR != "conc_reqs_busy" { + if capsConfigDIR != "caps_busy" { t.SkipNow() } var failedAPIs int @@ -254,7 +254,7 @@ func testCapsOnBiJSONBusy(t *testing.T) { } func testCapsOnBiJSONQueue(t *testing.T) { - if capsConfigDIR != "conc_reqs_queue" { + if capsConfigDIR != "caps_queue" { t.SkipNow() } wg := new(sync.WaitGroup) @@ -316,7 +316,7 @@ func benchmarkCall(b *testing.B) { } func BenchmarkcapsWithLimit(b *testing.B) { - benchmarkInit(b, "conc_reqs_queue_bench") + benchmarkInit(b, "caps_queue_bench") benchmarkCall(b) } diff --git a/config/config.go b/config/config.go index 6bca9a34a..50318a38a 100755 --- a/config/config.go +++ b/config/config.go @@ -399,7 +399,7 @@ func (cfg *CGRConfig) loadFromJSONCfg(jsnCfg *CgrJsonCfg) (err error) { cfg.loadLoaderCgrCfg, cfg.loadMigratorCgrCfg, cfg.loadTlsCgrCfg, cfg.loadAnalyzerCgrCfg, cfg.loadApierCfg, cfg.loadErsCfg, cfg.loadEesCfg, cfg.loadRateSCfg, cfg.loadSIPAgentCfg, cfg.loadDispatcherHCfg, - cfg.loadConfigSCfg, cfg.loadAPIBanCgrCfg} { + cfg.loadConfigSCfg, cfg.loadAPIBanCgrCfg, cfg.loadCoreSCfg} { if err = loadFunc(jsnCfg); err != nil { return } diff --git a/config/corescfg_test.go b/config/corescfg_test.go index eed25a51c..3d65ccbe9 100644 --- a/config/corescfg_test.go +++ b/config/corescfg_test.go @@ -40,13 +40,13 @@ func TestCoreSloadFromJsonCfg(t *testing.T) { } cfgJSONStr := `{ "cores": { - "caps": 0, // maximum concurrent request allowed ( 0 to disabled ) + "caps": 10, // maximum concurrent request allowed ( 0 to disabled ) "caps_strategy": "*busy", // strategy in case in case of concurrent requests reached "caps_stats_interval": "0" // the interval we sample for caps stats ( 0 to disabled ) }, }` expected = CoreSCfg{ - Caps: 0, + Caps: 10, CapsStrategy: utils.MetaBusy, CapsStatsInterval: 0, } diff --git a/cores/caps.go b/cores/caps.go index fed93551c..4fb5fade4 100644 --- a/cores/caps.go +++ b/cores/caps.go @@ -39,11 +39,10 @@ type Caps struct { // NewCaps creates a new caps func NewCaps(reqs int, strategy string) *Caps { - cR := &Caps{ + return &Caps{ strategy: strategy, aReqs: make(chan struct{}, reqs), } - return cR } // IsLimited returns true if the limit is not 0 diff --git a/data/conf/samples/conc_reqs_busy/cgrates.json b/data/conf/samples/caps_busy/cgrates.json similarity index 100% rename from data/conf/samples/conc_reqs_busy/cgrates.json rename to data/conf/samples/caps_busy/cgrates.json diff --git a/data/conf/samples/conc_reqs_queue/cgrates.json b/data/conf/samples/caps_queue/cgrates.json similarity index 100% rename from data/conf/samples/conc_reqs_queue/cgrates.json rename to data/conf/samples/caps_queue/cgrates.json diff --git a/data/conf/samples/conc_reqs_queue_bench/cgrates.json b/data/conf/samples/caps_queue_bench/cgrates.json similarity index 100% rename from data/conf/samples/conc_reqs_queue_bench/cgrates.json rename to data/conf/samples/caps_queue_bench/cgrates.json