sessions: ensure event is passed when updating session

This commit is contained in:
ionutboangiu
2025-09-01 21:21:26 +03:00
committed by Dan Christian Bogos
parent 788279596e
commit e81cb4fa9b
2 changed files with 18 additions and 11 deletions

View File

@@ -555,7 +555,7 @@ func (sS *SessionS) BiRPCv1UpdateSession(ctx *context.Context,
}
}
var sRunsUsage map[string]time.Duration
if sRunsUsage, err = sS.updateSession(ctx, s, nil, engine.MapEvent(args.APIOpts), dbtItvl); err != nil {
if sRunsUsage, err = sS.updateSession(ctx, s, engine.MapEvent(args.Event), engine.MapEvent(args.APIOpts), dbtItvl); err != nil {
return err
}

View File

@@ -541,7 +541,7 @@ func TestSessionLifecycle(t *testing.T) {
"sessions": {
"enabled": true,
"chargers_conns": ["*localhost"],
// "alterable_fields": ["AlterableField"],
"alterable_fields": ["AlterableField"],
"terminate_attempts": 1
},
"chargers": {
@@ -624,7 +624,7 @@ func TestSessionLifecycle(t *testing.T) {
}
}
checkActiveSessions := func(t *testing.T, wantCount int, filters ...string) {
checkActiveSessions := func(t *testing.T, wantCount int, filters ...string) []*ExternalSession {
t.Helper()
var sessions []*ExternalSession
if err := client.Call(context.Background(), utils.SessionSv1GetActiveSessions,
@@ -633,7 +633,7 @@ func TestSessionLifecycle(t *testing.T) {
}, &sessions); err != nil {
if wantCount == 0 && err.Error() == utils.ErrNotFound.Error() {
t.Logf("no active sessions found (expected)")
return
return nil
}
t.Fatalf("failed to get active sessions: %v", err)
}
@@ -642,6 +642,7 @@ func TestSessionLifecycle(t *testing.T) {
utils.SessionSv1GetActiveSessions, len(sessions), wantCount)
}
t.Logf("%s reply: %s", utils.SessionSv1GetActiveSessions, utils.ToIJSON(sessions))
return sessions
}
var replySetCharger string
@@ -661,14 +662,20 @@ func TestSessionLifecycle(t *testing.T) {
sessionID := "test-session-123"
initSession(t, sessionID)
checkActiveSessions(t, 1)
// TODO: Check if passing nil event is intended when updating sessions.
// Until then, skip testing UpdateSession API.
//
// updateSession(t, sessionID)
// checkActiveSessions(t, 1)
_ = updateSession // prevent compilation err
sessions := checkActiveSessions(t, 1)
want := "test_val"
if sessions[0].CGREvent.Event["AlterableField"] != want {
t.Errorf("after init, AlterableField = %v, want %s", sessions[0].CGREvent.Event["AlterableField"], want)
}
updateSession(t, sessionID)
sessions = checkActiveSessions(t, 1)
want = "new_val"
if sessions[0].CGREvent.Event["AlterableField"] != want {
t.Errorf("after update, AlterableField = %v, want %s", sessions[0].CGREvent.Event["AlterableField"], want)
}
termSession(t, sessionID)
checkActiveSessions(t, 0)