From afd09314c3581a6d38b7311d782a133ded02e342 Mon Sep 17 00:00:00 2001 From: DanB Date: Mon, 18 Sep 2017 18:18:06 +0200 Subject: [PATCH] StatS removeEventWithID tests --- engine/libstats.go | 18 +++++++++--------- engine/libstats_test.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/engine/libstats.go b/engine/libstats.go index 8f9b6b5e6..64dbdabbb 100755 --- a/engine/libstats.go +++ b/engine/libstats.go @@ -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(" 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(" metricID: %s, remove eventID: %s, error: %s", metricID, evTenantID, err.Error())) - } - } -} - // StatQueues is a sortable list of StatQueue type StatQueues []*StatQueue diff --git a/engine/libstats_test.go b/engine/libstats_test.go index 0e3230d7b..5817237a5 100644 --- a/engine/libstats_test.go +++ b/engine/libstats_test.go @@ -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) + } +}