Updated safevent tests

This commit is contained in:
Trial97
2019-06-28 09:23:07 +03:00
committed by Dan Christian Bogos
parent 28776358aa
commit 8d6b518869
8 changed files with 110 additions and 43 deletions

View File

@@ -21,6 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package agents
import (
"fmt"
"net/rpc"
"net/rpc/jsonrpc"
"os/exec"
@@ -278,9 +279,12 @@ func testRAitAcctStart(t *testing.T) {
}
var aSessions []*sessions.ExternalSession
if err := raRPC.Call(utils.SessionSv1GetActiveSessions,
map[string]string{utils.RunID: utils.META_DEFAULT,
utils.OriginID: "e4921177ab0e3586c37f6a185864b71a@0:0:0:0:0:0:0:0-51585361-75c2f57b"},
&aSessions); err != nil {
utils.SessionFilter{
Filters: []string{
fmt.Sprintf("*string:~%s:%s", utils.RunID, utils.META_DEFAULT),
fmt.Sprintf("*string:~%s:%s", utils.OriginID, "e4921177ab0e3586c37f6a185864b71a@0:0:0:0:0:0:0:0-51585361-75c2f57b"),
},
}, &aSessions); err != nil {
t.Error(err)
} else if len(aSessions) != 1 {
t.Errorf("Unexpected number of sessions received: %+v", aSessions)
@@ -346,8 +350,12 @@ func testRAitAcctStop(t *testing.T) {
// Make sure the sessin was disconnected from SMG
var aSessions []*sessions.ExternalSession
if err := raRPC.Call(utils.SessionSv1GetActiveSessions,
map[string]string{utils.RunID: utils.META_DEFAULT, utils.OriginID: "e4921177ab0e3586c37f6a185864b71a@0:0:0:0:0:0:0:0-51585361-75c2f57b"},
&aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() {
utils.SessionFilter{
Filters: []string{
fmt.Sprintf("*string:~%s:%s", utils.RunID, utils.META_DEFAULT),
fmt.Sprintf("*string:~%s:%s", utils.OriginID, "e4921177ab0e3586c37f6a185864b71a@0:0:0:0:0:0:0:0-51585361-75c2f57b"),
},
}, &aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Error(err)
}
time.Sleep(150 * time.Millisecond)

View File

@@ -685,7 +685,7 @@ func testDspSessionReplicate(t *testing.T) {
var repl int
time.Sleep(10 * time.Millisecond)
if err := allEngine2.RCP.Call(utils.SessionSv1GetPassiveSessionsCount,
map[string]string{}, &repl); err != nil {
nil, &repl); err != nil {
t.Fatal(err)
} else if repl != 2 {
t.Errorf("Expected 1 sessions recived %v", repl)

View File

@@ -814,19 +814,20 @@ func TestSafEventGetTInt64(t *testing.T) {
}
func TestSafEventGetDurationPtrIgnoreErrors(t *testing.T) {
safEv = &SafEvent{Me: NewMapEvent(sMap)}
if rply := safEv.GetDurationPtrIgnoreErrors("test"); rply != nil {
t.Errorf("Expected: %+v, received: %+v", nil, rply)
}
expected := utils.DurationPointer(time.Duration(10 * time.Second))
if rply := safEv.GetDurationPtrIgnoreErrors("test6"); *rply != *expected {
if rply := safEv.GetDurationPtrIgnoreErrors("test6"); rply == nil || *rply != *expected {
t.Errorf("Expected: %+v, received: %+v", expected, rply)
}
expected = utils.DurationPointer(time.Duration(42 * time.Second))
if rply := safEv.GetDurationPtrIgnoreErrors("test7"); *rply != *expected {
if rply := safEv.GetDurationPtrIgnoreErrors("test7"); rply == nil || *rply != *expected {
t.Errorf("Expected: %+v, received: %+v", expected, rply)
}
expected = utils.DurationPointer(time.Duration(42))
if rply := safEv.GetDurationPtrIgnoreErrors("test2"); *rply != *expected {
if rply := safEv.GetDurationPtrIgnoreErrors("test2"); rply == nil || *rply != *expected {
t.Errorf("Expected: %+v, received: %+v", expected, rply)
}
}

View File

@@ -172,7 +172,7 @@ func TestRPCITLclStatusFirstFailback(t *testing.T) {
// Make sure it executes on the first node supporting the command
func TestRPCITLclTDirectedRPC(t *testing.T) {
var sessions []*sessions.ExternalSession
if err := rpcPoolFirst.Call(utils.SessionSv1GetActiveSessions, map[string]string{}, &sessions); err == nil || err.Error() != utils.ErrNotFound.Error() {
if err := rpcPoolFirst.Call(utils.SessionSv1GetActiveSessions, nil, &sessions); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Error(err)
}
}

View File

@@ -394,7 +394,7 @@ func testCallGetActiveSessions(t *testing.T) {
},
}
if err := tutorialCallsRpc.Call(utils.SessionSv1GetActiveSessions,
&map[string]string{}, &reply); err != nil {
nil, &reply); err != nil {
t.Error("Got error on SessionSv1.GetActiveSessions: ", err.Error())
} else {
// compare some fields (eg. CGRId is generated)
@@ -688,7 +688,7 @@ func testCallSyncSessions(t *testing.T) {
var reply *[]*sessions.ExternalSession
// activeSessions shouldn't be active
if err := tutorialCallsRpc.Call(utils.SessionSv1GetActiveSessions,
&map[string]string{}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
nil, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Error("Got error on SessionSv1.GetActiveSessions: ", err)
}
// 1001 call 1002 stop the call after 12 seconds
@@ -706,7 +706,7 @@ func testCallSyncSessions(t *testing.T) {
time.Sleep(1 * time.Second)
// get active sessions
if err := tutorialCallsRpc.Call(utils.SessionSv1GetActiveSessions,
&map[string]string{}, &reply); err != nil {
nil, &reply); err != nil {
t.Error("Got error on SessionSv1.GetActiveSessions: ", err.Error())
} else if len(*reply) != 2 {
t.Errorf("expecting 2 active sessions, received: %+v", utils.ToJSON(reply))
@@ -757,7 +757,7 @@ func testCallSyncSessions(t *testing.T) {
// activeSessions shouldn't be active
if err := tutorialCallsRpc.Call(utils.SessionSv1GetActiveSessions,
&map[string]string{}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
nil, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Got error on SessionSv1.GetActiveSessions: %v and reply: %s", err, utils.ToJSON(reply))
}

View File

@@ -20,6 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package sessions
import (
"fmt"
"net/rpc"
"net/rpc/jsonrpc"
"path"
@@ -277,7 +278,11 @@ func TestSessionsItTerminatePassive(t *testing.T) {
var pSessions []*ExternalSession
//check if the passive session was created
if err := sItRPC.Call(utils.SessionSv1GetPassiveSessions,
map[string]string{utils.OriginID: "123789"}, &pSessions); err != nil {
utils.SessionFilter{
Filters: []string{
fmt.Sprintf("*string:~%s:%s", utils.OriginID, "123789"),
},
}, &pSessions); err != nil {
t.Error(err)
} else if len(pSessions) != 1 {
t.Errorf("Unexpected number of sessions received: %+v", pSessions)
@@ -315,7 +320,11 @@ func TestSessionsItTerminatePassive(t *testing.T) {
//check if the passive session was terminate
if err := sItRPC.Call(utils.SessionSv1GetPassiveSessions,
map[string]string{utils.OriginID: "123789"}, &pSessions); err == nil ||
utils.SessionFilter{
Filters: []string{
fmt.Sprintf("*string:~%s:%s", utils.OriginID, "123789"),
},
}, &pSessions); err == nil ||
err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Error: %v with len(aSessions)=%v , session : %+v", err, len(pSessions), utils.ToJSON(pSessions))
}

View File

@@ -20,6 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package sessions
import (
"fmt"
"net/rpc"
"net/rpc/jsonrpc"
"path"
@@ -136,7 +137,11 @@ func TestSessionSRplInitiate(t *testing.T) {
//check if the session was createad as active session on master
if err := smgRplcMstrRPC.Call(utils.SessionSv1GetActiveSessions,
map[string]string{utils.OriginID: "123451"}, &aSessions); err != nil {
utils.SessionFilter{
Filters: []string{
fmt.Sprintf("*string:~%s:%s", utils.OriginID, "123451"),
},
}, &aSessions); err != nil {
t.Error(err)
} else if len(aSessions) != 1 {
t.Errorf("Unexpected number of sessions received: %+v", utils.ToIJSON(aSessions))
@@ -147,7 +152,11 @@ func TestSessionSRplInitiate(t *testing.T) {
//check if the session was created as passive session on slave
var pSessions []*ExternalSession
if err := smgRplcSlvRPC.Call(utils.SessionSv1GetPassiveSessions,
map[string]string{utils.OriginID: "123451"}, &pSessions); err != nil {
utils.SessionFilter{
Filters: []string{
fmt.Sprintf("*string:~%s:%s", utils.OriginID, "123451"),
},
}, &pSessions); err != nil {
t.Error(err)
} else if len(pSessions) != 1 {
t.Errorf("PassiveSessions: %+v", pSessions)
@@ -192,7 +201,11 @@ func TestSessionSRplUpdate(t *testing.T) {
time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Wait for the sessions to be populated
var aSessions []*ExternalSession
if err := smgRplcSlvRPC.Call(utils.SessionSv1GetActiveSessions,
map[string]string{utils.OriginID: "123451"}, &aSessions); err != nil {
utils.SessionFilter{
Filters: []string{
fmt.Sprintf("*string:~%s:%s", utils.OriginID, "123451"),
},
}, &aSessions); err != nil {
t.Error(err)
} else if len(aSessions) != 1 {
t.Errorf("Unexpected number of sessions received: %+v", aSessions)
@@ -209,7 +222,11 @@ func TestSessionSRplUpdate(t *testing.T) {
// Master should not longer have activeSession
if err := smgRplcMstrRPC.Call(utils.SessionSv1GetActiveSessions,
map[string]string{utils.OriginID: "123451"}, &aSessions); err == nil ||
utils.SessionFilter{
Filters: []string{
fmt.Sprintf("*string:~%s:%s", utils.OriginID, "123451"),
},
}, &aSessions); err == nil ||
err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Error: %v with len(aSessions)=%v , session : %+v", err, len(aSessions), utils.ToJSON(aSessions))
}
@@ -258,7 +275,11 @@ func TestSessionSRplTerminate(t *testing.T) {
var aSessions []*ExternalSession
//check if the session was terminated on master
if err := smgRplcMstrRPC.Call(utils.SessionSv1GetActiveSessions,
map[string]string{utils.OriginID: "123451"}, &aSessions); err == nil ||
utils.SessionFilter{
Filters: []string{
fmt.Sprintf("*string:~%s:%s", utils.OriginID, "123451"),
},
}, &aSessions); err == nil ||
err.Error() != utils.ErrNotFound.Error() {
t.Errorf("Error: %v with len(aSessions)=%v , session : %+v", err, len(aSessions), utils.ToIJSON(aSessions))
}

View File

@@ -21,6 +21,7 @@ package sessions
import (
"flag"
"fmt"
"net/rpc"
"net/rpc/jsonrpc"
"path"
@@ -793,8 +794,12 @@ func TestSessionsVoiceSessionTTL(t *testing.T) {
var aSessions []*ExternalSession
if err := sessionsRPC.Call(utils.SessionSv1GetActiveSessions,
map[string]string{utils.RunID: utils.META_DEFAULT,
utils.OriginID: "12360"}, &aSessions); err != nil {
utils.SessionFilter{
Filters: []string{
fmt.Sprintf("*string:~%s:%s", utils.RunID, utils.META_DEFAULT),
fmt.Sprintf("*string:~%s:%s", utils.OriginID, "12360"),
},
}, &aSessions); err != nil {
t.Error(err)
} else if len(aSessions) != 1 {
t.Errorf("Unexpected number of sessions received: %+v", aSessions)
@@ -834,7 +839,7 @@ func TestSessionsVoiceSessionTTL(t *testing.T) {
var updateRpl *V1UpdateSessionReply
if err := sessionsRPC.Call(utils.SessionSv1UpdateSession, updateArgs, &updateRpl); err != nil {
t.Error(err)
t.Fatal(err)
}
time.Sleep(time.Duration(10 * time.Millisecond))
if *updateRpl.MaxUsage != usage {
@@ -842,8 +847,12 @@ func TestSessionsVoiceSessionTTL(t *testing.T) {
}
if err := sessionsRPC.Call(utils.SessionSv1GetActiveSessions,
map[string]string{utils.RunID: utils.META_DEFAULT, utils.OriginID: "12360"},
&aSessions); err != nil {
utils.SessionFilter{
Filters: []string{
fmt.Sprintf("*string:~%s:%s", utils.RunID, utils.META_DEFAULT),
fmt.Sprintf("*string:~%s:%s", utils.OriginID, "12360"),
},
}, &aSessions); err != nil {
t.Error(err)
} else if len(aSessions) != 1 {
t.Errorf("Unexpected number of sessions received: %+v", aSessions)
@@ -943,9 +952,12 @@ func TestSessionsVoiceSessionTTLWithRelocate(t *testing.T) {
var aSessions []*ExternalSession
if err := sessionsRPC.Call(utils.SessionSv1GetActiveSessions,
map[string]string{utils.RunID: utils.META_DEFAULT,
utils.OriginID: "12361"},
&aSessions); err != nil {
utils.SessionFilter{
Filters: []string{
fmt.Sprintf("*string:~%s:%s", utils.RunID, utils.META_DEFAULT),
fmt.Sprintf("*string:~%s:%s", utils.OriginID, "12361"),
},
}, &aSessions); err != nil {
t.Error(err)
} else if len(aSessions) != 1 {
t.Errorf("Unexpected number of sessions received: %+v", aSessions)
@@ -997,9 +1009,12 @@ func TestSessionsVoiceSessionTTLWithRelocate(t *testing.T) {
time.Sleep(time.Duration(20) * time.Millisecond)
if err := sessionsRPC.Call(utils.SessionSv1GetActiveSessions,
map[string]string{utils.RunID: utils.META_DEFAULT,
utils.OriginID: "12362"},
&aSessions); err != nil {
utils.SessionFilter{
Filters: []string{
fmt.Sprintf("*string:~%s:%s", utils.RunID, utils.META_DEFAULT),
fmt.Sprintf("*string:~%s:%s", utils.OriginID, "12362"),
},
}, &aSessions); err != nil {
t.Error(err)
} else if len(aSessions) != 1 {
t.Errorf("Unexpected number of sessions received: %+v", aSessions)
@@ -1024,9 +1039,12 @@ func TestSessionsVoiceSessionTTLWithRelocate(t *testing.T) {
eAcntVal, acnt.BalanceMap[utils.VOICE].GetTotalValue())
}
if err := sessionsRPC.Call(utils.SessionSv1GetActiveSessions,
map[string]string{utils.RunID: utils.META_DEFAULT,
utils.OriginID: "12362"},
&aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() {
utils.SessionFilter{
Filters: []string{
fmt.Sprintf("*string:~%s:%s", utils.RunID, utils.META_DEFAULT),
fmt.Sprintf("*string:~%s:%s", utils.OriginID, "12362"),
},
}, &aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Error(err, utils.ToJSON(aSessions))
}
time.Sleep(500 * time.Millisecond)
@@ -1104,9 +1122,12 @@ func TestSessionsVoiceRelocateWithOriginIDPrefix(t *testing.T) {
time.Sleep(time.Duration(20) * time.Millisecond)
var aSessions []*ExternalSession
if err := sessionsRPC.Call(utils.SessionSv1GetActiveSessions,
map[string]string{utils.RunID: utils.META_DEFAULT,
utils.OriginID: "12371"},
&aSessions); err != nil {
utils.SessionFilter{
Filters: []string{
fmt.Sprintf("*string:~%s:%s", utils.RunID, utils.META_DEFAULT),
fmt.Sprintf("*string:~%s:%s", utils.OriginID, "12371"),
},
}, &aSessions); err != nil {
t.Error(err)
} else if len(aSessions) != 1 {
t.Errorf("Unexpected number of sessions received: %+v", aSessions)
@@ -1158,8 +1179,12 @@ func TestSessionsVoiceRelocateWithOriginIDPrefix(t *testing.T) {
time.Sleep(time.Duration(20) * time.Millisecond)
if err := sessionsRPC.Call(utils.SessionSv1GetActiveSessions,
map[string]string{utils.RunID: utils.META_DEFAULT,
utils.OriginID: "12372-1"}, &aSessions); err != nil {
utils.SessionFilter{
Filters: []string{
fmt.Sprintf("*string:~%s:%s", utils.RunID, utils.META_DEFAULT),
fmt.Sprintf("*string:~%s:%s", utils.OriginID, "12372-1"),
},
}, &aSessions); err != nil {
t.Error(err)
} else if len(aSessions) != 1 {
t.Errorf("Unexpected number of sessions received: %+v", aSessions)
@@ -1204,8 +1229,12 @@ func TestSessionsVoiceRelocateWithOriginIDPrefix(t *testing.T) {
time.Sleep(time.Duration(10) * time.Millisecond)
if err := sessionsRPC.Call(utils.SessionSv1GetActiveSessions,
map[string]string{utils.RunID: utils.META_DEFAULT,
utils.OriginID: "12372-1"}, &aSessions); err == nil ||
utils.SessionFilter{
Filters: []string{
fmt.Sprintf("*string:~%s:%s", utils.RunID, utils.META_DEFAULT),
fmt.Sprintf("*string:~%s:%s", utils.OriginID, "12372-1"),
},
}, &aSessions); err == nil ||
err.Error() != utils.ErrNotFound.Error() {
t.Error(err, aSessions)
}
@@ -1283,7 +1312,6 @@ func TestSMGDataDerivedChargingNoCredit(t *testing.T) {
*/
// ToDo: Add test for ChargeEvent with derived charging, one with debit possible and second not so we see refund and error.CreditInsufficient showing up.
func TestSessionsVoiceStopCgrEngine(t *testing.T) {
if err := engine.KillEngine(1000); err != nil {
t.Error(err)