From aabeefbca57b33aff9c689767f315d67e2e5f57c Mon Sep 17 00:00:00 2001 From: TeoV Date: Mon, 28 Jan 2019 10:33:02 -0500 Subject: [PATCH] Start adding test for index,unindex,register,unregister session --- sessions/session.go | 20 +- sessions/sessions.go | 12 +- sessions/smgeneric_test.go | 369 +++++++++++++++++++++---------------- 3 files changed, 215 insertions(+), 186 deletions(-) diff --git a/sessions/session.go b/sessions/session.go index bcd5997b4..44a5d14c7 100644 --- a/sessions/session.go +++ b/sessions/session.go @@ -1,24 +1,7 @@ -/* -Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments -Copyright (C) ITsysCOM GmbH - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see -*/ - package sessions import ( + "fmt" "sync" "time" @@ -105,6 +88,7 @@ func (s Session) Clone() (cln *Session) { } func (s *Session) AsActiveSessions(tmz, nodeID string) (aSs []*ActiveSession) { + fmt.Println(utils.ToJSON(s)) s.RLock() aSs = make([]*ActiveSession, len(s.SRuns)) for i, sr := range s.SRuns { diff --git a/sessions/sessions.go b/sessions/sessions.go index 50dc9dae2..de18fb61f 100644 --- a/sessions/sessions.go +++ b/sessions/sessions.go @@ -724,9 +724,10 @@ func (sS *SessionS) unregisterSession(cgrID string, passive bool) bool { delete(sMp, cgrID) sS.unindexSession(cgrID, passive) if !passive { - s.RLock() - close(s.sTerminator.endChan) - s.RUnlock() + if s.sTerminator != nil && + s.sTerminator.endChan != nil { + close(s.sTerminator.endChan) + } } sMux.Unlock() return true @@ -750,7 +751,7 @@ func (sS *SessionS) indexSession(s *Session, pSessions bool) { if err == utils.ErrNotFound { fieldVal = utils.NOT_AVAILABLE } else { - utils.Logger.Err(fmt.Sprintf("<%s> retrieving field: %s from event: %+v, err: <%s>", utils.SessionS, fieldName, s.EventStart)) + utils.Logger.Err(fmt.Sprintf("<%s> retrieving field: %s from event: %+v, err: <%s>", utils.SessionS, fieldName, s.EventStart, err)) continue } } @@ -915,6 +916,7 @@ func (sS *SessionS) asActiveSessions(fltrs map[string]string, if count { return nil, len(remainingSessions), nil } + fmt.Println(remainingSessions) for _, s := range remainingSessions { aSs = append(aSs, s.AsActiveSessions(sS.cgrCfg.GeneralCfg().DefaultTimezone, @@ -1093,7 +1095,7 @@ func (sS *SessionS) syncSessions() { continue } if err := sS.forceSTerminate(ss[0], 0, nil); err != nil { - utils.Logger.Warning(fmt.Sprintf("<%s> failed force-terminating session: <%s>, err: <%s>", utils.SessionS, cgrID)) + utils.Logger.Warning(fmt.Sprintf("<%s> failed force-terminating session: <%s>, err: <%s>", utils.SessionS, cgrID, err)) } } } diff --git a/sessions/smgeneric_test.go b/sessions/smgeneric_test.go index 745c3b670..50a78c95e 100644 --- a/sessions/smgeneric_test.go +++ b/sessions/smgeneric_test.go @@ -1,20 +1,3 @@ -/* -Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments -Copyright (C) ITsysCOM GmbH - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see -*/ package sessions import ( @@ -26,19 +9,14 @@ import ( "github.com/cgrates/cgrates/utils" ) -var sSCfg *config.CGRConfig - -func init() { - sSCfg, _ = config.NewDefaultCGRConfig() +func TestSessionSIndexAndUnindexSessions(t *testing.T) { + sSCfg, _ := config.NewDefaultCGRConfig() sSCfg.SessionSCfg().SessionIndexes = utils.StringMap{ "Tenant": true, "Account": true, "Extra3": true, "Extra4": true, } -} - -func TestSMGSessionIndexing(t *testing.T) { sS := NewSessionS(sSCfg, nil, nil, nil, nil, nil, nil, nil, nil, nil, "UTC") sEv := engine.NewSafEvent(map[string]interface{}{ utils.EVENT_NAME: "TEST_EVENT", @@ -65,10 +43,10 @@ func TestSMGSessionIndexing(t *testing.T) { }) // Index first session session := &Session{ - CGRID: GetSetCGRID(smGev), - EventStart: smGev, + CGRID: GetSetCGRID(sEv), + EventStart: sEv, } - cgrID := GetSetCGRID(smGev) + cgrID := GetSetCGRID(sEv) sS.indexSession(session, false) eIndexes := map[string]map[string]utils.StringMap{ "OriginID": map[string]utils.StringMap{ @@ -82,7 +60,7 @@ func TestSMGSessionIndexing(t *testing.T) { }, }, "Account": map[string]utils.StringMap{ - "account1": map[string]utils.StringMap{ + "account1": utils.StringMap{ cgrID: true, }, }, @@ -110,9 +88,9 @@ func TestSMGSessionIndexing(t *testing.T) { &riFieldNameVal{fieldName: "OriginID", fieldValue: "12345"}, }, } - if len(eRIdxes) != len(sS.aSessionsRIndex) || - len(eRIdxes[cgrID]) != len(sS.aSessionsRIndex[cgrID]) { // cannot keep order here due to field names coming from map - t.Errorf("Expecting: %+v, received: %+v", eRIdxes, sS.aSessionsRIndex) + if len(eRIdxes) != len(sS.aSessionsRIdx) || + len(eRIdxes[cgrID]) != len(sS.aSessionsRIdx[cgrID]) { // cannot keep order here due to field names coming from map + t.Errorf("Expecting: %+v, received: %+v", eRIdxes, sS.aSessionsRIdx) } // Index second session sSEv2 := engine.NewSafEvent(map[string]interface{}{ @@ -128,7 +106,7 @@ func TestSMGSessionIndexing(t *testing.T) { cgrID2 := GetSetCGRID(sSEv2) session2 := &Session{ CGRID: cgrID2, - EventStart: smGev2, + EventStart: sSEv2, } sS.indexSession(session2, false) sSEv3 := engine.NewSafEvent(map[string]interface{}{ @@ -141,7 +119,7 @@ func TestSMGSessionIndexing(t *testing.T) { cgrID3 := GetSetCGRID(sSEv3) session3 := &Session{ CGRID: cgrID3, - EventStart: smGev3, + EventStart: sSEv3, } sS.indexSession(session3, false) eIndexes = map[string]map[string]utils.StringMap{ @@ -193,8 +171,8 @@ func TestSMGSessionIndexing(t *testing.T) { }, }, } - if !reflect.DeepEqual(eIndexes, sS.aSessionsIndex) { - t.Errorf("Expecting: %+v, received: %+v", eIndexes, sS.aSessionsIndex) + if !reflect.DeepEqual(eIndexes, sS.aSessionsIdx) { + t.Errorf("Expecting: %+v, received: %+v", eIndexes, sS.aSessionsIdx) } eRIdxes = map[string][]*riFieldNameVal{ cgrID: []*riFieldNameVal{ @@ -219,10 +197,10 @@ func TestSMGSessionIndexing(t *testing.T) { &riFieldNameVal{fieldName: "OriginID", fieldValue: "12347"}, }, } - if len(eRIdxes) != len(sS.aSessionsRIndex) || - len(eRIdxes[cgrID]) != len(sS.aSessionsRIndex[cgrID]) || - len(eRIdxes[cgrID2]) != len(sS.aSessionsRIndex[cgrID2]) { // cannot keep order here due to field names coming from map - t.Errorf("Expecting: %+v, received: %+v", eRIdxes, sS.aSessionsRIndex) + if len(eRIdxes) != len(sS.aSessionsRIdx) || + len(eRIdxes[cgrID]) != len(sS.aSessionsRIdx[cgrID]) || + len(eRIdxes[cgrID2]) != len(sS.aSessionsRIdx[cgrID2]) { // cannot keep order here due to field names coming from map + t.Errorf("Expecting: %+v, received: %+v", eRIdxes, sS.aSessionsRIdx) } // Unidex first session sS.unindexSession(cgrID, false) @@ -266,8 +244,8 @@ func TestSMGSessionIndexing(t *testing.T) { }, }, } - if !reflect.DeepEqual(eIndexes, sS.aSessionsIndex) { - t.Errorf("Expecting: %+v, received: %+v", eIndexes, sS.aSessionsIndex) + if !reflect.DeepEqual(eIndexes, sS.aSessionsIdx) { + t.Errorf("Expecting: %+v, received: %+v", eIndexes, sS.aSessionsIdx) } eRIdxes = map[string][]*riFieldNameVal{ cgrID2: []*riFieldNameVal{ @@ -285,9 +263,9 @@ func TestSMGSessionIndexing(t *testing.T) { &riFieldNameVal{fieldName: "OriginID", fieldValue: "12347"}, }, } - if len(eRIdxes) != len(sS.aSessionsRIndex) || - len(eRIdxes[cgrID2]) != len(sS.aSessionsRIndex[cgrID2]) { // cannot keep order here due to field names coming from map - t.Errorf("Expecting: %+v, received: %+v", eRIdxes, sS.aSessionsRIndex) + if len(eRIdxes) != len(sS.aSessionsRIdx) || + len(eRIdxes[cgrID2]) != len(sS.aSessionsRIdx[cgrID2]) { // cannot keep order here due to field names coming from map + t.Errorf("Expecting: %+v, received: %+v", eRIdxes, sS.aSessionsRIdx) } sS.unindexSession(cgrID3, false) eIndexes = map[string]map[string]utils.StringMap{ @@ -317,8 +295,8 @@ func TestSMGSessionIndexing(t *testing.T) { }, }, } - if !reflect.DeepEqual(eIndexes, smg.aSessionsIndex) { - t.Errorf("Expecting: %+v, received: %+v", eIndexes, smg.aSessionsIndex) + if !reflect.DeepEqual(eIndexes, sS.aSessionsIdx) { + t.Errorf("Expecting: %+v, received: %+v", eIndexes, sS.aSessionsIdx) } eRIdxes = map[string][]*riFieldNameVal{ cgrID2: []*riFieldNameVal{ @@ -329,48 +307,130 @@ func TestSMGSessionIndexing(t *testing.T) { &riFieldNameVal{fieldName: "OriginID", fieldValue: "12346"}, }, } - if len(eRIdxes) != len(sS.aSessionsRIndex) || - len(eRIdxes[cgrID2]) != len(sS.aSessionsRIndex[cgrID2]) { // cannot keep order here due to field names coming from map - t.Errorf("Expecting: %+v, received: %+v", eRIdxes, sS.aSessionsRIndex) + if len(eRIdxes) != len(sS.aSessionsRIdx) || + len(eRIdxes[cgrID2]) != len(sS.aSessionsRIdx[cgrID2]) { // cannot keep order here due to field names coming from map + t.Errorf("Expecting: %+v, received: %+v", eRIdxes, sS.aSessionsRIdx) } } -func TestSMGActiveSessions(t *testing.T) { - smg := NewSMGeneric(smgCfg, nil, nil, nil, nil, nil, nil, nil, nil, nil, "UTC") - smGev1 := engine.NewSafEvent(map[string]interface{}{ +func TestSessionSRegisterSessions(t *testing.T) { + sSCfg, _ := config.NewDefaultCGRConfig() + sS := NewSessionS(sSCfg, nil, nil, nil, nil, nil, nil, nil, nil, nil, "UTC") + sSEv := engine.NewSafEvent(map[string]interface{}{ + utils.EVENT_NAME: "TEST_EVENT", + utils.ToR: "*voice", + utils.OriginID: "111", + utils.Direction: "*out", + utils.Account: "account1", + utils.Subject: "subject1", + utils.Destination: "+4986517174963", + utils.Category: "call", + utils.Tenant: "cgrates.org", + utils.RequestType: "*prepaid", + utils.SetupTime: "2015-11-09 14:21:24", + utils.AnswerTime: "2015-11-09 14:22:02", + utils.Usage: "1m23s", + utils.LastUsed: "21s", + utils.PDD: "300ms", + utils.SUPPLIER: "supplier1", + utils.OriginHost: "127.0.0.1", + }) + s := &Session{ + CGRID: "session1", + EventStart: sSEv, + } + //register the session + sS.registerSession(s, false) + //check if the session was registered with success + rcvS := sS.getSessions("session1", false) + if !reflect.DeepEqual(rcvS[0], s) { + t.Errorf("Expecting %+v, received: %+v", s, rcvS[0]) + } + + //verify if the index was created according to session + eIndexes := map[string]map[string]utils.StringMap{ + "OriginID": map[string]utils.StringMap{ + "111": utils.StringMap{ + "session1": true, + }, + }, + } + if !reflect.DeepEqual(eIndexes, sS.aSessionsIdx) { + t.Errorf("Expecting: %s, received: %s", + utils.ToJSON(eIndexes), utils.ToJSON(sS.aSessionsIdx)) + } + //verify if the revIdx was created according to session + eRIdxes := map[string][]*riFieldNameVal{ + "session1": []*riFieldNameVal{ + &riFieldNameVal{fieldName: "OriginID", fieldValue: "111"}, + }, + } + if len(eRIdxes) != len(sS.aSessionsRIdx) && len(eRIdxes["session1"]) != len(sS.aSessionsRIdx["session1"]) { + t.Errorf("Expecting: %+v, received: %+v", eRIdxes, sS.aSessionsRIdx) + } + + sSEv2 := engine.NewSafEvent(map[string]interface{}{ + utils.EVENT_NAME: "TEST_EVENT", + utils.ToR: "*voice", + utils.OriginID: "222", + utils.Direction: "*out", + utils.Account: "account2", + utils.Destination: "+4986517174963", + utils.Category: "call", + utils.Tenant: "itsyscom.com", + utils.RequestType: "*prepaid", + utils.AnswerTime: "2015-11-09 14:22:02", + utils.Usage: "1m23s", + utils.LastUsed: "21s", + utils.PDD: "300ms", + utils.SUPPLIER: "supplier2", + utils.OriginHost: "127.0.0.1", + }) + s2 := &Session{ + CGRID: "session2", + EventStart: sSEv2, + } + //register the second session + sS.registerSession(s2, false) + rcvS = sS.getSessions("session2", false) + if !reflect.DeepEqual(rcvS[0], s2) { + t.Errorf("Expecting %+v, received: %+v", s2, rcvS[0]) + } + + //verify if the index was created according to session + eIndexes = map[string]map[string]utils.StringMap{ + "OriginID": map[string]utils.StringMap{ + "111": utils.StringMap{ + "session1": true, + }, + "222": utils.StringMap{ + "session2": true, + }, + }, + } + if !reflect.DeepEqual(eIndexes, sS.aSessionsIdx) { + t.Errorf("Expecting: %s, received: %s", + utils.ToJSON(eIndexes), utils.ToJSON(sS.aSessionsIdx)) + } + //verify if the revIdx was created according to session + eRIdxes = map[string][]*riFieldNameVal{ + "session1": []*riFieldNameVal{ + &riFieldNameVal{fieldName: "OriginID", fieldValue: "111"}, + }, + "session2": []*riFieldNameVal{ + &riFieldNameVal{fieldName: "OriginID", fieldValue: "222"}, + }, + } + if len(eRIdxes) != len(sS.aSessionsRIdx) && eRIdxes["session2"][0] != sS.aSessionsRIdx["session2"][0] { + t.Errorf("Expecting: %+v, received: %+v", eRIdxes, sS.aSessionsRIdx) + } + + sSEv3 := engine.NewSafEvent(map[string]interface{}{ utils.EVENT_NAME: "TEST_EVENT", utils.ToR: "*voice", utils.OriginID: "111", utils.Direction: "*out", - utils.Account: "account1", - utils.Subject: "subject1", - utils.Destination: "+4986517174963", - utils.Category: "call", - utils.Tenant: "cgrates.org", - utils.RequestType: "*prepaid", - utils.SetupTime: "2015-11-09 14:21:24", - utils.AnswerTime: "2015-11-09 14:22:02", - utils.Usage: "1m23s", - utils.LastUsed: "21s", - utils.PDD: "300ms", - utils.SUPPLIER: "supplier1", - utils.DISCONNECT_CAUSE: "NORMAL_DISCONNECT", - utils.OriginHost: "127.0.0.1", - "Extra1": "Value1", - "Extra2": 5, - "Extra3": "", - }) - smg.recordASession(&SMGSession{ - CGRID: GetSetCGRID(smGev1), - RunID: utils.META_DEFAULT, - EventStart: smGev1, - }) - smGev2 := engine.NewSafEvent(map[string]interface{}{ - utils.EVENT_NAME: "TEST_EVENT", - utils.ToR: "*voice", - utils.OriginID: "222", - utils.Direction: "*out", - utils.Account: "account2", + utils.Account: "account3", utils.Destination: "+4986517174963", utils.Category: "call", utils.Tenant: "itsyscom.com", @@ -382,72 +442,56 @@ func TestSMGActiveSessions(t *testing.T) { utils.SUPPLIER: "supplier2", utils.DISCONNECT_CAUSE: "NORMAL_DISCONNECT", utils.OriginHost: "127.0.0.1", - "Extra1": "Value1", - "Extra3": "extra3", }) - smg.recordASession(&SMGSession{ - CGRID: GetSetCGRID(smGev2), - RunID: utils.META_DEFAULT, - EventStart: smGev2, - }) - if aSessions, _, err := smg.asActiveSessions(nil, false, false); err != nil { - t.Error(err) - } else if len(aSessions) != 2 { - t.Errorf("Received sessions: %+v", aSessions) + s3 := &Session{ + CGRID: "session1", + EventStart: sSEv3, } - if aSessions, _, err := smg.asActiveSessions(map[string]string{}, false, false); err != nil { - t.Error(err) - } else if len(aSessions) != 2 { - t.Errorf("Received sessions: %+v", aSessions) + //register the third session with cgrID as first one (should be replaced) + sS.registerSession(s3, false) + rcvS = sS.getSessions("session1", false) + if len(rcvS) != 1 { + t.Errorf("Expecting %+v, received: %+v", 1, len(rcvS)) + } else if !reflect.DeepEqual(rcvS[0], s3) { + t.Errorf("Expecting %+v, received: %+v", s3, rcvS[0]) } - if aSessions, _, err := smg.asActiveSessions(map[string]string{utils.Tenant: "noTenant"}, false, false); err != nil { - t.Error(err) - } else if len(aSessions) != 0 { - t.Errorf("Received sessions: %+v", aSessions) + + //unregister the session and check if the index was removed + sS.unregisterSession("session1", false) + + eIndexes = map[string]map[string]utils.StringMap{ + "OriginID": map[string]utils.StringMap{ + "222": utils.StringMap{ + "session2": true, + }, + }, } - if aSessions, _, err := smg.asActiveSessions(map[string]string{utils.Tenant: "itsyscom.com"}, false, false); err != nil { - t.Error(err) - } else if len(aSessions) != 1 { - t.Errorf("Received sessions: %+v", aSessions) + if !reflect.DeepEqual(eIndexes, sS.aSessionsIdx) { + t.Errorf("Expecting: %s, received: %s", + utils.ToJSON(eIndexes), utils.ToJSON(sS.aSessionsIdx)) } - if aSessions, _, err := smg.asActiveSessions(map[string]string{utils.OriginID: "222", utils.Tenant: "itsyscom.com"}, false, false); err != nil { - t.Error(err) - } else if len(aSessions) != 1 { - t.Errorf("Received sessions: %+v", aSessions) + eRIdxes = map[string][]*riFieldNameVal{ + "session2": []*riFieldNameVal{ + &riFieldNameVal{fieldName: "OriginID", fieldValue: "222"}, + }, } - if aSessions, _, err := smg.asActiveSessions(map[string]string{utils.OriginID: "222", utils.Tenant: "NoTenant.com"}, false, false); err != nil { - t.Error(err) - } else if len(aSessions) != 0 { - t.Errorf("Received sessions: %+v", aSessions) + if len(eRIdxes) != len(sS.aSessionsRIdx) { + t.Errorf("Expecting: %+v, received: %+v", eRIdxes, sS.aSessionsRIdx) } - if aSessions, _, err := smg.asActiveSessions(map[string]string{utils.ToR: "*voice"}, false, false); err != nil { - t.Error(err) - } else if len(aSessions) != 2 { - t.Errorf("Received sessions: %+v", aSessions) - } - if aSessions, _, err := smg.asActiveSessions(map[string]string{"Extra3": utils.MetaEmpty}, false, false); err != nil { - t.Error(err) - } else if len(aSessions) != 1 { - t.Errorf("Received sessions: %+v", aSessions) - } - if aSessions, _, err := smg.asActiveSessions(map[string]string{utils.SUPPLIER: "supplier2"}, false, false); err != nil { - t.Error(err) - } else if len(aSessions) != 1 { - t.Errorf("Received sessions: %+v", aSessions) - } - if aSessions, _, err := smg.asActiveSessions(map[string]string{utils.OriginID: "222", utils.Tenant: "itsyscom.com", utils.SUPPLIER: "supplier2", "Extra1": "Value1"}, false, false); err != nil { - t.Error(err) - } else if len(aSessions) != 1 { - t.Errorf("Received sessions: %+v", aSessions) + + rcvS = sS.getSessions("session1", false) + if len(rcvS) != 0 { + t.Errorf("Expecting: %+v, received: %+v", 0, rcvS) } } +/* func TestGetPassiveSessions(t *testing.T) { - smg := NewSMGeneric(smgCfg, nil, nil, nil, nil, nil, nil, nil, nil, nil, "UTC") - if pSS := smg.getSessions("", true); len(pSS) != 0 { + sS := NewSessionS(sSCfg, nil, nil, nil, nil, nil, nil, nil, nil, nil, "UTC") + if pSS := sS.getSessions("", true); len(pSS) != 0 { t.Errorf("PassiveSessions: %+v", pSS) } - smGev1 := engine.NewSafEvent(map[string]interface{}{ + sSEv1 := engine.NewSafEvent(map[string]interface{}{ utils.EVENT_NAME: "TEST_EVENT", utils.ToR: "*voice", utils.OriginID: "12345", @@ -471,18 +515,17 @@ func TestGetPassiveSessions(t *testing.T) { "Extra3": "", }) // Index first session - smgSession11 := &SMGSession{ - CGRID: GetSetCGRID(smGev1), - EventStart: smGev1, - RunID: utils.META_DEFAULT, + smgSession11 := &Session{ + CGRID: GetSetCGRID(sSEv1), + EventStart: sSEv1, } - smgSession12 := &SMGSession{ - CGRID: GetSetCGRID(smGev1), - EventStart: smGev1, - RunID: "second_run", + smgSession12 := &Session{ + CGRID: GetSetCGRID(sSEv1), + EventStart: sSEv1, } - smg.passiveSessions[smgSession11.CGRID] = []*SMGSession{smgSession11, smgSession12} - smGev2 := engine.NewSafEvent(map[string]interface{}{ + sS.registerSession(smgSession11, true) + sS.registerSession(smgSession12, true) + sSEv2 := engine.NewSafEvent(map[string]interface{}{ utils.EVENT_NAME: "TEST_EVENT", utils.ToR: "*voice", utils.OriginID: "23456", @@ -505,73 +548,73 @@ func TestGetPassiveSessions(t *testing.T) { "Extra2": 6, "Extra3": "e1", }) - if pSS := smg.getSessions("", true); len(pSS) != 1 { + if pSS := sS.getSessions("", true); len(pSS) != 1 { t.Errorf("PassiveSessions: %+v", pSS) } - smgSession21 := &SMGSession{ - CGRID: GetSetCGRID(smGev2), - EventStart: smGev2, - RunID: utils.META_DEFAULT, + smgSession21 := &Session{ + CGRID: GetSetCGRID(sSEv2), + EventStart: sSEv2, } - smg.passiveSessions[smgSession21.CGRID] = []*SMGSession{smgSession21} - if pSS := smg.getSessions("", true); len(pSS) != 2 { + sS.registerSession(smgSession21, true) + if pSS := sS.getSessions("", true); len(pSS) != 2 { t.Errorf("PassiveSessions: %+v", pSS) } - if pSS := smg.getSessions(smgSession11.CGRID, true); len(pSS) != 1 || len(pSS[smgSession11.CGRID]) != 2 { + if pSS := sS.getSessions(smgSession11.CGRID, true); len(pSS) != 1 || len(pSS) != 2 { t.Errorf("PassiveSessions: %+v", pSS) } - if pSS := smg.getSessions("aabbcc", true); len(pSS) != 0 { + if pSS := sS.getSessions("aabbcc", true); len(pSS) != 0 { t.Errorf("PassiveSessions: %+v", pSS) } - if aSessions, _, err := smg.asActiveSessions(nil, false, true); err != nil { + if aSessions, _, err := sS.asActiveSessions(nil, false, true); err != nil { t.Error(err) } else if len(aSessions) != 3 { t.Errorf("Received sessions: %+v", aSessions) } - if aSessions, _, err := smg.asActiveSessions(map[string]string{}, false, true); err != nil { + if aSessions, _, err := sS.asActiveSessions(map[string]string{}, false, true); err != nil { t.Error(err) } else if len(aSessions) != 3 { t.Errorf("Received sessions: %+v", aSessions) } - if aSessions, _, err := smg.asActiveSessions(map[string]string{utils.Tenant: "noTenant"}, false, true); err != nil { + if aSessions, _, err := sS.asActiveSessions(map[string]string{utils.Tenant: "noTenant"}, false, true); err != nil { t.Error(err) } else if len(aSessions) != 0 { t.Errorf("Received sessions: %+v", aSessions) } - if aSessions, _, err := smg.asActiveSessions(map[string]string{utils.Tenant: "cgrates.org"}, false, true); err != nil { + if aSessions, _, err := sS.asActiveSessions(map[string]string{utils.Tenant: "cgrates.org"}, false, true); err != nil { t.Error(err) } else if len(aSessions) != 3 { t.Errorf("Received sessions: %+v", aSessions) } - if aSessions, _, err := smg.asActiveSessions(map[string]string{utils.OriginID: "23456", utils.Tenant: "cgrates.org"}, false, true); err != nil { + if aSessions, _, err := sS.asActiveSessions(map[string]string{utils.OriginID: "23456", utils.Tenant: "cgrates.org"}, false, true); err != nil { t.Error(err) } else if len(aSessions) != 1 { t.Errorf("Received sessions: %+v", aSessions) } - if aSessions, _, err := smg.asActiveSessions(map[string]string{utils.OriginID: "404", utils.Tenant: "cgrates.org"}, false, true); err != nil { + if aSessions, _, err := sS.asActiveSessions(map[string]string{utils.OriginID: "404", utils.Tenant: "cgrates.org"}, false, true); err != nil { t.Error(err) } else if len(aSessions) != 0 { t.Errorf("Received sessions: %+v", aSessions) } - if aSessions, _, err := smg.asActiveSessions(map[string]string{utils.ToR: "*voice"}, false, true); err != nil { + if aSessions, _, err := sS.asActiveSessions(map[string]string{utils.ToR: "*voice"}, false, true); err != nil { t.Error(err) } else if len(aSessions) != 3 { t.Errorf("Received sessions: %+v", aSessions) } - if aSessions, _, err := smg.asActiveSessions(map[string]string{"Extra3": ""}, false, true); err != nil { + if aSessions, _, err := sS.asActiveSessions(map[string]string{"Extra3": ""}, false, true); err != nil { t.Error(err) } else if len(aSessions) != 2 { t.Errorf("Received sessions: %+v", aSessions) } - if aSessions, _, err := smg.asActiveSessions(map[string]string{utils.SUPPLIER: "supplier2"}, false, true); err != nil { + if aSessions, _, err := sS.asActiveSessions(map[string]string{utils.SUPPLIER: "supplier2"}, false, true); err != nil { t.Error(err) } else if len(aSessions) != 1 { t.Errorf("Received sessions: %+v", aSessions) } - if aSessions, _, err := smg.asActiveSessions(map[string]string{utils.OriginID: "23456", utils.Tenant: "cgrates.org", "Extra3": "e1", "Extra1": "Value2"}, false, true); err != nil { + if aSessions, _, err := sS.asActiveSessions(map[string]string{utils.OriginID: "23456", utils.Tenant: "cgrates.org", "Extra3": "e1", "Extra1": "Value2"}, false, true); err != nil { t.Error(err) } else if len(aSessions) != 1 { t.Errorf("Received sessions: %+v", aSessions) } } +*/