diff --git a/data/conf/samples/smgreplcslave/cgrates.json b/data/conf/samples/smgreplcslave/cgrates.json index 97d0f9470..0502a9554 100644 --- a/data/conf/samples/smgreplcslave/cgrates.json +++ b/data/conf/samples/smgreplcslave/cgrates.json @@ -20,6 +20,9 @@ "sm_generic": { "enabled": true, // starts SessionManager service: "listen_bijson": "127.0.0.1:22014", // address where to listen for bidirectional JSON-RPC requests + "smg_replication_conns": [ + {"address": "127.0.0.1:2012", "transport": "*json"}, + ], }, } diff --git a/sessionmanager/smgeneric.go b/sessionmanager/smgeneric.go index 5e381316f..372d6798e 100644 --- a/sessionmanager/smgeneric.go +++ b/sessionmanager/smgeneric.go @@ -675,14 +675,15 @@ func (smg *SMGeneric) TerminateSession(gev SMGenericEvent, clnt rpcclient.RpcCli var hasActiveSession bool for _, sessionID := range sessionIDs { defer smg.replicateSessions(sessionID) - var s *SMGSession - for _, s = range smg.getASession(sessionID) { - break - } - if s == nil { - continue // No session active, will not be able to close it anyway + aSessions := smg.getASession(sessionID) + if len(aSessions) == 0 { + if aSessions = smg.passiveToActive(cgrID); len(aSessions) == 0 { + utils.Logger.Err(fmt.Sprintf(" SessionTerminate with no active sessions for cgrID: <%s>", cgrID)) + continue + } } hasActiveSession = true + s := aSessions[0] if errUsage != nil { usage = s.TotalUsage - s.LastUsage + lastUsed } diff --git a/sessionmanager/smgreplc_it_test.go b/sessionmanager/smgreplc_it_test.go index fbc40a7c7..a469c8391 100644 --- a/sessionmanager/smgreplc_it_test.go +++ b/sessionmanager/smgreplc_it_test.go @@ -182,19 +182,21 @@ func TestSMGRplcUpdate(t *testing.T) { if err := smgRplcSlvRPC.Call("SMGenericV1.GetPassiveSessions", ArgsGetPassiveSessions{}, &pSessions); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) } - /* - cgrID := smgEv.GetCGRID(utils.META_DEFAULT) - // Make sure session was replicated - if err := smgRplcMstrRPC.Call("SMGenericV1.GetPassiveSessions", ArgsGetPassiveSessions{}, &pSessions); err != nil { - t.Error(err) - } else if len(pSessions) != 1 { - t.Errorf("PassiveSessions: %+v", pSessions) - } else if _, hasOriginID := pSessions[cgrID]; !hasOriginID { - t.Errorf("PassiveSessions: %+v", pSessions) - } else if pSessions[cgrID][0].TotalUsage != time.Duration(150*time.Second) { - t.Errorf("PassiveSession: %+v", pSessions[cgrID][0]) - } - */ + // Master should not longer have activeSession + if err := smgRplcMstrRPC.Call("SMGenericV1.ActiveSessions", utils.AttrSMGGetActiveSessions{OriginID: utils.StringPointer("123451")}, &aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() { + t.Error(err) + } + cgrID := smgEv.GetCGRID(utils.META_DEFAULT) + // Make sure session was replicated + if err := smgRplcMstrRPC.Call("SMGenericV1.GetPassiveSessions", ArgsGetPassiveSessions{}, &pSessions); err != nil { + t.Error(err) + } else if len(pSessions) != 1 { + t.Errorf("PassiveSessions: %+v", pSessions) + } else if _, hasOriginID := pSessions[cgrID]; !hasOriginID { + t.Errorf("PassiveSessions: %+v", pSessions) + } else if pSessions[cgrID][0].TotalUsage != time.Duration(150*time.Second) { + t.Errorf("PassiveSession: %+v", pSessions[cgrID][0]) + } } @@ -208,15 +210,21 @@ func TestSMGRplcTerminate(t *testing.T) { utils.USAGE: "3m", } var reply string - if err := smgRplcSlvRPC.Call("SMGenericV1.TerminateSession", smgEv, &reply); err != nil { + if err := smgRplcMstrRPC.Call("SMGenericV1.TerminateSession", smgEv, &reply); err != nil { t.Error(err) } time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Wait for the sessions to be populated var aSessions []*ActiveSession + if err := smgRplcMstrRPC.Call("SMGenericV1.ActiveSessions", utils.AttrSMGGetActiveSessions{OriginID: utils.StringPointer("123451")}, &aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() { + t.Error(err, aSessions) + } if err := smgRplcSlvRPC.Call("SMGenericV1.ActiveSessions", utils.AttrSMGGetActiveSessions{OriginID: utils.StringPointer("123451")}, &aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err, aSessions) } var pSessions map[string][]*SMGSession + if err := smgRplcMstrRPC.Call("SMGenericV1.GetPassiveSessions", ArgsGetPassiveSessions{}, &pSessions); err == nil || err.Error() != utils.ErrNotFound.Error() { + t.Error(err) + } if err := smgRplcSlvRPC.Call("SMGenericV1.GetPassiveSessions", ArgsGetPassiveSessions{}, &pSessions); err == nil || err.Error() != utils.ErrNotFound.Error() { t.Error(err) }