Added test for caps with cache

This commit is contained in:
Trial97
2020-11-26 08:59:48 +02:00
committed by Dan Christian Bogos
parent 128e678ef2
commit 062cb5272b

View File

@@ -24,6 +24,7 @@ import (
"testing"
"time"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/utils"
)
@@ -144,3 +145,44 @@ func TestFloatDP(t *testing.T) {
t.Errorf("Expected: %v ,received:%v", exp, s)
}
}
func TestCapsStatsGetAverageOnEvict(t *testing.T) {
st, err := NewStatAverage(1, utils.MetaDynReq, nil)
if err != nil {
t.Error(err)
}
cs := &CapsStats{st: st}
cfg, _ := config.NewDefaultCGRConfig()
cfg.CacheCfg().Partitions[utils.CacheCapsEvents] = &config.CacheParamCfg{Limit: 2}
tmp := Cache
Cache = NewCacheS(cfg, nil, cs)
cs.addSample("1", 10)
expAvg := 10.
if avg := cs.GetAverage(2); avg != expAvg {
t.Errorf("Expected: %v ,received: %v", expAvg, avg)
}
expPk := 10
if pk := cs.GetPeak(); pk != expPk {
t.Errorf("Expected: %v ,received:%v", expPk, pk)
}
cs.addSample("2", 16)
expAvg = 13.
if avg := cs.GetAverage(2); avg != expAvg {
t.Errorf("Expected: %v ,received: %v", expAvg, avg)
}
expPk = 16
if pk := cs.GetPeak(); pk != expPk {
t.Errorf("Expected: %v ,received:%v", expPk, pk)
}
cs.addSample("3", 18)
expAvg = 17.
if avg := cs.GetAverage(2); avg != expAvg {
t.Errorf("Expected: %v ,received: %v", expAvg, avg)
}
expPk = 18
if pk := cs.GetPeak(); pk != expPk {
t.Errorf("Expected: %v ,received:%v", expPk, pk)
}
Cache = tmp
}