Simplified SMGeneric.ttlTerminate to avoid loops via updateSession

This commit is contained in:
DanB
2016-04-18 18:06:15 +02:00
parent 69ece5cb94
commit 2c118eb954
3 changed files with 8 additions and 10 deletions

View File

@@ -27,7 +27,7 @@
"enabled": true,
"rater": "internal",
"cdrs": "internal",
"session_ttl": "10ms",
"session_ttl": "50ms",
},
}

View File

@@ -687,13 +687,13 @@ func TestSMGVoiceSessionTTL(t *testing.T) {
t.Errorf("Expected: %f, received: %f", eAcntVal, acnt.BalanceMap[utils.MONETARY].GetTotalValue())
}
time.Sleep(50 * time.Millisecond)
time.Sleep(100 * time.Millisecond)
if err := smgRPC.Call("SMGenericV1.ActiveSessions", utils.AttrSMGGetActiveSessions{RunID: utils.StringPointer(utils.META_DEFAULT), OriginID: utils.StringPointer("12360")}, &aSessions); err != nil {
t.Error(err)
} else if len(aSessions) != 1 {
t.Errorf("Unexpected number of sessions received: %+v", aSessions)
} else if aSessions[0].Usage != time.Duration(150)*time.Second+time.Duration(10)*time.Millisecond {
t.Errorf("Expecting 2m30s10ms, received usage: %v", aSessions[0].Usage)
} else if aSessions[0].Usage != time.Duration(150)*time.Second+time.Duration(50)*time.Millisecond {
t.Errorf("Expecting 2m30s50ms, received usage: %v", aSessions[0].Usage)
}
/*

View File

@@ -78,15 +78,13 @@ func (self *SMGeneric) resetTerminatorTimer(uuid string, ttl time.Duration, ttlL
// Called when a session timeouts
func (self *SMGeneric) ttlTerminate(s *SMGSession, tmtr *smgSessionTerminator) {
evUpdate := s.eventStart
evUpdate[utils.USAGE] = tmtr.ttl.Seconds()
debitUsage := tmtr.ttl
if tmtr.ttlUsage != nil {
evUpdate[utils.USAGE] = tmtr.ttlUsage.Seconds()
debitUsage = *tmtr.ttlUsage
}
if tmtr.ttlLastUsed != nil {
evUpdate[utils.LastUsed] = tmtr.ttlLastUsed.Seconds()
for _, s := range self.getSession(s.eventStart.GetUUID()) {
s.debit(debitUsage, tmtr.ttlLastUsed)
}
self.SessionUpdate(evUpdate, nil)
/*self.sessionEnd(s.eventStart.GetUUID(), s.TotalUsage())
cdr := s.eventStart.AsStoredCdr(self.cgrCfg, self.timezone)
cdr.Usage = s.TotalUsage()