mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
StatS removeEventWithID tests
This commit is contained in:
@@ -163,6 +163,15 @@ func (sq *StatQueue) ProcessEvent(ev StatEvent) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// remStatEvent removes an event from metrics
|
||||
func (sq *StatQueue) remEventWithID(evTenantID string) {
|
||||
for metricID, metric := range sq.SQMetrics {
|
||||
if err := metric.RemEvent(evTenantID); err != nil {
|
||||
utils.Logger.Warning(fmt.Sprintf("<StatQueue> metricID: %s, remove eventID: %s, error: %s", metricID, evTenantID, err.Error()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// remExpired expires items in queue
|
||||
func (sq *StatQueue) remExpired() {
|
||||
var expIdx *int // index of last item to be expired
|
||||
@@ -205,15 +214,6 @@ func (sq *StatQueue) addStatEvent(ev StatEvent) {
|
||||
}
|
||||
}
|
||||
|
||||
// remStatEvent removes an event from metrics
|
||||
func (sq *StatQueue) remEventWithID(evTenantID string) {
|
||||
for metricID, metric := range sq.SQMetrics {
|
||||
if err := metric.RemEvent(evTenantID); err != nil {
|
||||
utils.Logger.Warning(fmt.Sprintf("<StatQueue> metricID: %s, remove eventID: %s, error: %s", metricID, evTenantID, err.Error()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// StatQueues is a sortable list of StatQueue
|
||||
type StatQueues []*StatQueue
|
||||
|
||||
|
||||
@@ -20,8 +20,12 @@ package engine
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
var sq *StatQueue
|
||||
|
||||
func TestStatQueuesSort(t *testing.T) {
|
||||
sInsts := StatQueues{
|
||||
&StatQueue{sqPrfl: &StatQueueProfile{ID: "FIRST", Weight: 30.0}},
|
||||
@@ -40,3 +44,29 @@ func TestStatQueuesSort(t *testing.T) {
|
||||
t.Errorf("expecting: %+v, received: %+v", eSInst, sInsts)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemEventWithID(t *testing.T) {
|
||||
sq = &StatQueue{
|
||||
SQMetrics: map[string]StatMetric{
|
||||
utils.MetaASR: &StatASR{
|
||||
Answered: 1,
|
||||
Count: 2,
|
||||
Events: map[string]bool{
|
||||
"cgrates.org:TestRemEventWithID_1": true,
|
||||
"cgrates.org:TestRemEventWithID_2": false,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
if asrIf := sq.SQMetrics[utils.MetaASR].GetValue(); asrIf.(float64) != 50 {
|
||||
t.Errorf("received ASR: %v", asrIf)
|
||||
}
|
||||
sq.remEventWithID("cgrates.org:TestRemEventWithID_1")
|
||||
if asrIf := sq.SQMetrics[utils.MetaASR].GetValue(); asrIf.(float64) != 0 {
|
||||
t.Errorf("received ASR: %v", asrIf)
|
||||
}
|
||||
sq.remEventWithID("cgrates.org:TestRemEventWithID_2")
|
||||
if asrIf := sq.SQMetrics[utils.MetaASR].GetValue(); asrIf.(float64) != -1 {
|
||||
t.Errorf("received ASR: %v", asrIf)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user