From ae808ca7ed2022991e84d1fc0b5c4785273d312f Mon Sep 17 00:00:00 2001 From: Trial97 Date: Wed, 22 Jul 2020 15:44:52 +0300 Subject: [PATCH] Updated AttributeSv1.ProccessEvent to not match the same profile multiple time in a row --- apier/v1/attributes_it_test.go | 8 ++++--- engine/attributes.go | 26 +++++++++++++--------- engine/z_attributes_test.go | 15 ++++++++----- general_tests/cdrs_processevent_it_test.go | 15 ++++++------- 4 files changed, 36 insertions(+), 28 deletions(-) diff --git a/apier/v1/attributes_it_test.go b/apier/v1/attributes_it_test.go index 74c4e64b7..923cde54a 100644 --- a/apier/v1/attributes_it_test.go +++ b/apier/v1/attributes_it_test.go @@ -480,7 +480,9 @@ func testAttributeSProcessEventWithNoneSubstitute(t *testing.T) { if err := attrSRPC.Call(utils.AttributeSv1ProcessEvent, ev, &rplyEv); err != nil { t.Error(err) - } else if !reflect.DeepEqual(eRply, &rplyEv) { + } + sort.Strings(rplyEv.AlteredFields) + if !reflect.DeepEqual(eRply, &rplyEv) { t.Errorf("Expecting: %s, received: %s", utils.ToJSON(eRply), utils.ToJSON(rplyEv)) } @@ -1063,7 +1065,7 @@ func testAttributeSProcessWithMultipleRuns(t *testing.T) { }, } eRply := &engine.AttrSProcessEventReply{ - MatchedProfiles: []string{"ATTR_1", "ATTR_2"}, + MatchedProfiles: []string{"ATTR_1", "ATTR_2", "ATTR_1", "ATTR_2"}, AlteredFields: []string{"*req.Field1", "*req.Field2"}, CGREvent: &utils.CGREvent{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, @@ -1173,7 +1175,7 @@ func testAttributeSProcessWithMultipleRuns2(t *testing.T) { }, } eRply := &engine.AttrSProcessEventReply{ - MatchedProfiles: []string{"ATTR_1", "ATTR_2", "ATTR_3"}, + MatchedProfiles: []string{"ATTR_1", "ATTR_2", "ATTR_3", "ATTR_2"}, AlteredFields: []string{"*req.Field1", "*req.Field2", "*req.Field3"}, CGREvent: &utils.CGREvent{ Tenant: config.CgrConfig().GeneralCfg().DefaultTenant, diff --git a/engine/attributes.go b/engine/attributes.go index 8faf4983e..31b4d7313 100644 --- a/engine/attributes.go +++ b/engine/attributes.go @@ -333,13 +333,16 @@ func (alS *AttributeService) processEvent(args *AttrArgsProcessEvent, evNm utils } if attribute.Type == utils.META_COMPOSED { var val string - if val, err = evNm.FieldAsString(strings.Split(attribute.Path, utils.NestingSep)); err != nil { + if val, err = evNm.FieldAsString(strings.Split(attribute.Path, utils.NestingSep)); err != nil && err != utils.ErrNotFound { rply = nil return } substitute = val + substitute } - evNm.Set(strings.Split(attribute.Path, utils.NestingSep), substitute) + if err = evNm.Set(strings.Split(attribute.Path, utils.NestingSep), substitute); err != nil { + rply = nil + return + } } return } @@ -413,16 +416,17 @@ func (alS *AttributeService) V1ProcessEvent(args *AttrArgsProcessEvent, break } } - if err != nil { - return - } - // Make sure the requested fields were populated - for field, val := range args.CGREvent.Event { - if val == utils.MetaAttributes { - // mandatory IE missing - err = utils.NewErrMandatoryIeMissing(field) - return + if err == nil || err == utils.ErrNotFound { + // Make sure the requested fields were populated + for field, val := range args.CGREvent.Event { + if val == utils.MetaAttributes { + // mandatory IE missing + err = utils.NewErrMandatoryIeMissing(field) + return + } } + } else { + return } *reply = AttrSProcessEventReply{ diff --git a/engine/z_attributes_test.go b/engine/z_attributes_test.go index f1b8ce788..c19a84707 100644 --- a/engine/z_attributes_test.go +++ b/engine/z_attributes_test.go @@ -19,6 +19,7 @@ package engine import ( "reflect" + "sort" "testing" "time" @@ -588,6 +589,7 @@ func TestAttributeProcessWithMultipleRuns1(t *testing.T) { if !reflect.DeepEqual(eRply.MatchedProfiles, reply.MatchedProfiles) { t.Fatalf("Expecting %+v, received: %+v", eRply.MatchedProfiles, reply.MatchedProfiles) } + sort.Strings(reply.AlteredFields) if !reflect.DeepEqual(eRply.AlteredFields, reply.AlteredFields) { t.Errorf("Expecting %+v, received: %+v", eRply.AlteredFields, reply.AlteredFields) } @@ -676,7 +678,7 @@ func TestAttributeProcessWithMultipleRuns2(t *testing.T) { }, } eRply := &AttrSProcessEventReply{ - MatchedProfiles: []string{"ATTR_1", "ATTR_2"}, + MatchedProfiles: []string{"ATTR_1", "ATTR_2", "ATTR_1", "ATTR_2"}, AlteredFields: []string{utils.MetaReq + utils.NestingSep + "Field1", utils.MetaReq + utils.NestingSep + "Field2"}, CGREvent: &utils.CGREvent{ @@ -696,6 +698,7 @@ func TestAttributeProcessWithMultipleRuns2(t *testing.T) { if !reflect.DeepEqual(eRply.MatchedProfiles, reply.MatchedProfiles) { t.Errorf("Expecting %+v, received: %+v", eRply.MatchedProfiles, reply.MatchedProfiles) } + sort.Strings(reply.AlteredFields) if !reflect.DeepEqual(eRply.AlteredFields, reply.AlteredFields) { t.Errorf("Expecting %+v, received: %+v", eRply.AlteredFields, reply.AlteredFields) } @@ -704,8 +707,6 @@ func TestAttributeProcessWithMultipleRuns2(t *testing.T) { } } -/* - func TestAttributeProcessWithMultipleRuns3(t *testing.T) { //refresh the DM if err := dmAtr.DataDB().Flush(""); err != nil { @@ -875,7 +876,7 @@ func TestAttributeProcessWithMultipleRuns4(t *testing.T) { }, } eRply := &AttrSProcessEventReply{ - MatchedProfiles: []string{"ATTR_1", "ATTR_2"}, + MatchedProfiles: []string{"ATTR_1", "ATTR_2", "ATTR_1", "ATTR_2"}, AlteredFields: []string{utils.MetaReq + utils.NestingSep + "Field1", utils.MetaReq + utils.NestingSep + "Field2"}, CGREvent: &utils.CGREvent{ @@ -895,6 +896,7 @@ func TestAttributeProcessWithMultipleRuns4(t *testing.T) { if !reflect.DeepEqual(eRply.MatchedProfiles, reply.MatchedProfiles) { t.Errorf("Expecting %+v, received: %+v", eRply.MatchedProfiles, reply.MatchedProfiles) } + sort.Strings(reply.AlteredFields) if !reflect.DeepEqual(eRply.AlteredFields, reply.AlteredFields) { t.Errorf("Expecting %+v, received: %+v", eRply.AlteredFields, reply.AlteredFields) } @@ -1006,6 +1008,7 @@ func TestAttributeMultipleProcessWithBlocker(t *testing.T) { if !reflect.DeepEqual(eRply.MatchedProfiles, reply.MatchedProfiles) { t.Errorf("Expecting %+v, received: %+v", eRply.MatchedProfiles, reply.MatchedProfiles) } + sort.Strings(reply.AlteredFields) if !reflect.DeepEqual(eRply.AlteredFields, reply.AlteredFields) { t.Errorf("Expecting %+v, received: %+v", eRply.AlteredFields, reply.AlteredFields) } @@ -1264,6 +1267,7 @@ func TestAttributeAttributeFilterIDs(t *testing.T) { if !reflect.DeepEqual(eRply.MatchedProfiles, reply.MatchedProfiles) { t.Errorf("Expecting %+v, received: %+v", eRply.MatchedProfiles, reply.MatchedProfiles) } + sort.Strings(reply.AlteredFields) if !reflect.DeepEqual(eRply.AlteredFields, reply.AlteredFields) { t.Errorf("Expecting %+v, received: %+v", eRply.AlteredFields, reply.AlteredFields) } @@ -1491,7 +1495,7 @@ func TestAttributeProcessEventComposed(t *testing.T) { } var reply AttrSProcessEventReply if err := attrService.V1ProcessEvent(attrArgs, &reply); err != nil { - t.Errorf("Error: %+v", err) + t.Fatalf("Error: %+v", err) } if !reflect.DeepEqual(eRply.MatchedProfiles, reply.MatchedProfiles) { t.Errorf("Expecting %+v, received: %+v", eRply.MatchedProfiles, reply.MatchedProfiles) @@ -2547,4 +2551,3 @@ func TestAttributeIndexSelectsFalse(t *testing.T) { } } -*/ diff --git a/general_tests/cdrs_processevent_it_test.go b/general_tests/cdrs_processevent_it_test.go index 5a5983e0f..10b2b4b7b 100644 --- a/general_tests/cdrs_processevent_it_test.go +++ b/general_tests/cdrs_processevent_it_test.go @@ -272,12 +272,12 @@ func testV1CDRsProcessEventChrgS(t *testing.T) { t.Errorf("Expecting: test2_processEvent, received: %+v, %+v, %+v ", cdrs[0].OriginID, cdrs[1].OriginID, cdrs[2].OriginID) } sort.Slice(cdrs, func(i, j int) bool { return cdrs[i].RunID < cdrs[j].RunID }) - if cdrs[1].RunID != "raw" { // charger with RunID *raw - t.Errorf("Expecting: %+v, received: %+v", "raw", cdrs[1].RunID) + if cdrs[2].RunID != "raw" { // charger with RunID *raw + t.Errorf("Expecting: %+v, received: %+v", "raw", cdrs[2].RunID) } else if cdrs[0].RunID != "CustomerCharges" { t.Errorf("Expecting: %+v, received: %+v", "CustomerCharges", cdrs[0].RunID) - } else if cdrs[2].RunID != "SupplierCharges" { - t.Errorf("Expecting: %+v, received: %+v", "SupplierCharges", cdrs[2].RunID) + } else if cdrs[1].RunID != "SupplierCharges" { + t.Errorf("Expecting: %+v, received: %+v", "SupplierCharges", cdrs[1].RunID) } } @@ -347,7 +347,7 @@ func testV1CDRsProcessEventSts(t *testing.T) { } var cdrs []*engine.CDR eOut := []*engine.CDR{ - &engine.CDR{ + { CGRID: "c87609aa1cb6e9529ab1836cfeeebaab7aa7ebaf", RunID: "testv1", OrderID: 0, @@ -440,9 +440,8 @@ func testV1CDRsProcessEventThreshold(t *testing.T) { if err := pecdrsRpc.Call(utils.APIerSv2SetActions, &utils.AttrSetActions{ ActionsId: "ACT_LOG", Actions: []*utils.TPAction{ - &utils.TPAction{ - Identifier: utils.LOG}, - &utils.TPAction{ + {Identifier: utils.LOG}, + { Identifier: utils.TOPUP_RESET, BalanceType: utils.VOICE, Units: "10", ExpiryTime: "*unlimited", DestinationIds: "*any", BalanceWeight: "10", Weight: 10},