Updated caps integration tests

This commit is contained in:
Trial97
2020-11-05 14:20:23 +02:00
committed by Dan Christian Bogos
parent 6af358e55e
commit 044311888d
7 changed files with 15 additions and 16 deletions

View File

@@ -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)
}

View File

@@ -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
}

View File

@@ -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,
}

View File

@@ -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