Updated AttributeSv1.ProccessEvent to not match the same profile multiple time in a row

This commit is contained in:
Trial97
2020-07-22 15:44:52 +03:00
committed by Dan Christian Bogos
parent 2471b89803
commit ae808ca7ed
4 changed files with 36 additions and 28 deletions

View File

@@ -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,

View File

@@ -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{

View File

@@ -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) {
}
}
*/

View File

@@ -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},