From e81cb4fa9b10363c577413103349f9941acaf8b5 Mon Sep 17 00:00:00 2001 From: ionutboangiu Date: Mon, 1 Sep 2025 21:21:26 +0300 Subject: [PATCH] sessions: ensure event is passed when updating session --- sessions/apis.go | 2 +- sessions/basics_it_test.go | 27 +++++++++++++++++---------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/sessions/apis.go b/sessions/apis.go index 63f2304d6..5acf8adf3 100644 --- a/sessions/apis.go +++ b/sessions/apis.go @@ -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 } diff --git a/sessions/basics_it_test.go b/sessions/basics_it_test.go index c57791577..dc26cf3cc 100644 --- a/sessions/basics_it_test.go +++ b/sessions/basics_it_test.go @@ -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)