Added *apiban precache integration test

This commit is contained in:
Trial97
2020-09-25 12:46:05 +03:00
committed by Dan Christian Bogos
parent 0bc0b58a69
commit 64ae4f16d5
7 changed files with 30 additions and 7 deletions

View File

@@ -246,7 +246,9 @@ func testCacheSReload(t *testing.T) {
if err := chcRPC.Call(utils.CacheSv1GetCacheStats, &utils.AttrCacheIDsWithOpts{}, &rcvStats); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(expStats, rcvStats) {
}
rcvStats[utils.MetaAPIBan].Items = 0
if !reflect.DeepEqual(expStats, rcvStats) {
t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(expStats), utils.ToJSON(rcvStats))
}
}
@@ -442,8 +444,10 @@ func testCacheSPrecacheStatus(t *testing.T) {
expected[k] = utils.MetaReady
}
if err := chcRPC.Call(utils.CacheSv1PrecacheStatus, &utils.AttrCacheIDsWithOpts{}, &reply); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(expected, reply) {
t.Fatal(err)
}
reply[utils.MetaAPIBan] = utils.MetaReady // do not check the status for this partition
if !reflect.DeepEqual(expected, reply) {
t.Errorf("Expected: %v , received:%v", utils.ToJSON(expected), utils.ToJSON(reply))
}
}

View File

@@ -54,6 +54,8 @@ var (
}
)
// this tests may fail because of apiban limit( 5 requests per 2 minutes for an APIKey)
// if needed add more APIKeys
func TestPrecacheIT(t *testing.T) {
switch *dbType {
case utils.MetaInternal:
@@ -146,6 +148,7 @@ func testPrecacheRestartEngine(t *testing.T) {
if err != nil {
t.Fatal("Could not connect to rater: ", err.Error())
}
time.Sleep(2 * time.Second) // let the *apiban cache to be populated
}
func testPrecacheGetCacheStatsAfterRestart(t *testing.T) {
@@ -302,6 +305,7 @@ func testPrecacheGetCacheStatsAfterRestart(t *testing.T) {
utils.CacheTBLTPDispatchers: {},
utils.CacheTBLTPDispatcherHosts: {},
utils.CacheTBLTPRateProfiles: {},
utils.MetaAPIBan: {Items: 254},
}
if err := precacheRPC.Call(utils.CacheSv1GetCacheStats, args, &reply); err != nil {
t.Error(err.Error())

View File

@@ -57,7 +57,8 @@
"*charger_filter_indexes" : {"limit": 10000, "ttl":"0s", "precache": true},
"*dispatcher_profiles" : {"limit": 10000, "ttl":"0s", "precache": true},
"*dispatcher_hosts" : {"limit": 10000, "ttl":"0s", "precache": true},
"*dispatcher_routes" : {"limit": 10000, "ttl":"0s", "precache": false}
"*dispatcher_routes" : {"limit": 10000, "ttl":"0s", "precache": false},
"*apiban" : {"limit": 254, "ttl":"0s", "precache": true}
},
},
@@ -89,4 +90,9 @@
},
"apiban": {
"keys": ["4c8140a0d7ec506e03ac59283eea8a9a", "559bbfa6808558b3197bf4960bbc1635", "2efdcd5d3d1b3a3ab4d71636b7b6d847"],
},
}

View File

@@ -53,7 +53,8 @@
"*charger_filter_indexes" : {"limit": 10000, "ttl":"0s", "precache": true},
"*dispatcher_profiles" : {"limit": 10000, "ttl":"0s", "precache": true},
"*dispatcher_hosts" : {"limit": 10000, "ttl":"0s", "precache": true},
"*dispatcher_routes" : {"limit": 10000, "ttl":"0s", "precache": false}
"*dispatcher_routes" : {"limit": 10000, "ttl":"0s", "precache": false},
"*apiban" : {"limit": 254, "ttl":"0s", "precache": true}
},
},
@@ -80,4 +81,9 @@
},
"apiban": {
"keys": ["4c8140a0d7ec506e03ac59283eea8a9a", "559bbfa6808558b3197bf4960bbc1635", "2efdcd5d3d1b3a3ab4d71636b7b6d847"],
},
}

View File

@@ -240,6 +240,7 @@ func testDspChcPrecacheStatus(t *testing.T) {
utils.CacheTBLTPDispatchers: utils.MetaReady,
utils.CacheTBLTPDispatcherHosts: utils.MetaReady,
utils.CacheTBLTPRateProfiles: utils.MetaReady,
utils.MetaAPIBan: utils.MetaReady,
}
if err := dispEngine.RPC.Call(utils.CacheSv1PrecacheStatus, utils.AttrCacheIDsWithOpts{

View File

@@ -135,8 +135,9 @@ func (dm *DataManager) CacheDataFromDB(prfx string, ids []string, mustBeCached b
if dm.cacheCfg.Partitions[utils.CachePrefixToInstance[prfx]].Limit == 0 {
return
}
if ids == nil &&
prfx != utils.MetaAPIBan { // no need for ids in this case
if prfx == utils.MetaAPIBan { // no need for ids in this case
ids = []string{utils.EmptyString}
} else if ids == nil {
if mustBeCached {
ids = Cache.GetItemIDs(utils.CachePrefixToInstance[prfx], utils.EmptyString)
} else {

View File

@@ -520,6 +520,7 @@ func GetDefaultEmptyCacheStats() map[string]*ltcache.CacheStats {
utils.CacheUCH: {},
utils.CacheEventCharges: {},
utils.CacheReverseFilterIndexes: {},
utils.MetaAPIBan: {},
utils.CacheAccounts: {},
utils.CacheVersions: {},