From 8b9a5f4e4fbadecf76535c82e37a8a16fa0e87b0 Mon Sep 17 00:00:00 2001 From: TeoV Date: Thu, 5 Jul 2018 06:45:19 -0400 Subject: [PATCH] Update test after filter indexing --- apier/v1/resourcesv1_it_test.go | 1 + apier/v1/thresholds_it_test.go | 24 ++++++++++++------------ engine/thresholds.go | 5 +++-- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/apier/v1/resourcesv1_it_test.go b/apier/v1/resourcesv1_it_test.go index 6a1de0e65..895e9d0af 100644 --- a/apier/v1/resourcesv1_it_test.go +++ b/apier/v1/resourcesv1_it_test.go @@ -143,6 +143,7 @@ func testV1RsGetResourcesForEvent(t *testing.T) { if err := rlsV1Rpc.Call(utils.ResourceSv1GetResourcesForEvent, args, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } + time.Sleep(time.Duration(500) * time.Millisecond) args.CGREvent.Event = map[string]interface{}{"Destination": "10", "Account": "1001"} if err := rlsV1Rpc.Call(utils.ResourceSv1GetResourcesForEvent, args, &reply); err != nil { t.Error(err) diff --git a/apier/v1/thresholds_it_test.go b/apier/v1/thresholds_it_test.go index eaa4d8514..0c38401bc 100644 --- a/apier/v1/thresholds_it_test.go +++ b/apier/v1/thresholds_it_test.go @@ -49,7 +49,8 @@ var tEvs = []*utils.CGREvent{ utils.EventType: utils.AccountUpdate, utils.Account: "1002", utils.AllowNegative: true, - utils.Disabled: false}}, + utils.Disabled: false, + utils.Units: 12.3}}, &utils.CGREvent{ // hitting THD_ACNT_BALANCE_1 Tenant: "cgrates.org", ID: "event2", @@ -253,10 +254,9 @@ func testV1TSGetThresholds(t *testing.T) { func testV1TSProcessEvent(t *testing.T) { var ids []string eIDs := []string{} - if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, tEvs[0], &ids); err != nil { + if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, tEvs[0], &ids); err == nil || + err.Error() != utils.ErrNotFound.Error() { t.Error(err) - } else if !reflect.DeepEqual(ids, eIDs) { - t.Errorf("Expecting ids: %s, received: %s", eIDs, ids) } eIDs = []string{"THD_ACNT_BALANCE_1"} if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, tEvs[1], &ids); err != nil { @@ -369,13 +369,13 @@ func testV1TSSetThresholdProfile(t *testing.T) { t.Error("Unexpected reply returned", result) } if err := tSv1Rpc.Call("ApierV1.GetThresholdProfile", - &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &reply); err == nil || + &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Test"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } tPrfl = &engine.ThresholdProfile{ Tenant: "cgrates.org", - ID: "TEST_PROFILE1", + ID: "THD_Test", FilterIDs: []string{"TestFilter"}, ActivationInterval: &utils.ActivationInterval{ ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC), @@ -394,7 +394,7 @@ func testV1TSSetThresholdProfile(t *testing.T) { t.Error("Unexpected reply returned", result) } if err := tSv1Rpc.Call("ApierV1.GetThresholdProfile", - &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &reply); err != nil { + &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Test"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(tPrfl, reply) { t.Errorf("Expecting: %+v, received: %+v", tPrfl, reply) @@ -408,8 +408,8 @@ func testV1TSUpdateThresholdProfile(t *testing.T) { ID: "TestFilter2", Rules: []*engine.FilterRule{ &engine.FilterRule{ - FieldName: "*string", - Type: "Account", + FieldName: "*prefix", + Type: "Destination", Values: []string{"10", "20"}, }, }, @@ -433,7 +433,7 @@ func testV1TSUpdateThresholdProfile(t *testing.T) { time.Sleep(time.Duration(100 * time.Millisecond)) // mongo is async var reply *engine.ThresholdProfile if err := tSv1Rpc.Call("ApierV1.GetThresholdProfile", - &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &reply); err != nil { + &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Test"}, &reply); err != nil { t.Error(err) } else if !reflect.DeepEqual(tPrfl, reply) { t.Errorf("Expecting: %+v, received: %+v", tPrfl, reply) @@ -443,14 +443,14 @@ func testV1TSUpdateThresholdProfile(t *testing.T) { func testV1TSRemoveThresholdProfile(t *testing.T) { var resp string if err := tSv1Rpc.Call("ApierV1.RemoveThresholdProfile", - &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &resp); err != nil { + &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Test"}, &resp); err != nil { t.Error(err) } else if resp != utils.OK { t.Error("Unexpected reply returned", resp) } var sqp *engine.ThresholdProfile if err := tSv1Rpc.Call("ApierV1.GetThresholdProfile", - &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &sqp); err == nil || + &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Test"}, &sqp); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } diff --git a/engine/thresholds.go b/engine/thresholds.go index b6ee97a2f..b1fa66a4a 100644 --- a/engine/thresholds.go +++ b/engine/thresholds.go @@ -323,9 +323,10 @@ func (tS *ThresholdService) processEvent(args *ArgsProcessEvent) (thresholdsIDs tS.stMux.Unlock() } } - if len(tIDs) != 0 { - thresholdsIDs = append(thresholdsIDs, tIDs...) + if len(tIDs) == 0 { + return nil, utils.ErrNotFound } + thresholdsIDs = append(thresholdsIDs, tIDs...) if withErrors { err = utils.ErrPartiallyExecuted }