Skip to content

Commit 44e2ab3

Browse files
test(audience-session): reset starts a new session, does not emit session_end
Pin the M2-A1 fix (commit dc286a0e): Reset must end the old session silently, mint a fresh anonymousId, and fire session_start for the new session. Matches Web SDK reset(). - Reset_StartsNewSession_DoesNotEmitSessionEnd: new session_start present, no session_end on disk, new anonymousId differs from the first. - Reset_ConsentNone_DoesNotStartSession: at None consent, Reset must not spin up a new session (no session_start emitted). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent bd0de3a commit 44e2ab3

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

src/Packages/Audience/Tests/Runtime/Core/SessionTests.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,57 @@ public void OnPauseAndOnResume_BeforeInit_AreNoOps()
882882
Assert.DoesNotThrow(() => ImmutableAudience.OnResume());
883883
}
884884

885+
[Test]
886+
public void Reset_StartsNewSession_DoesNotEmitSessionEnd()
887+
{
888+
// Reset must end the old session and start a new one so subsequent
889+
// Track events carry a fresh sessionId alongside the fresh
890+
// anonymousId — matches Web SDK reset() semantics. The old
891+
// session's session_end is enqueued by Session.Dispose but wiped
892+
// by the PurgeAll in Reset, so the wire sees only a session_start
893+
// for the new session.
894+
ImmutableAudience.Init(MakeConfig(ConsentLevel.Anonymous));
895+
896+
// Drain game_launch + session_start for the initial session so we
897+
// only see post-Reset events.
898+
ImmutableAudience.FlushQueueToDiskForTesting();
899+
var queueDir = Path.Combine(_testDir, "imtbl_audience", "queue");
900+
foreach (var f in Directory.GetFiles(queueDir, "*.json")) File.Delete(f);
901+
902+
var firstAnonymousId = Identity.Get(_testDir);
903+
Assert.IsNotNull(firstAnonymousId, "first session should have minted an anonymousId");
904+
905+
ImmutableAudience.Reset();
906+
ImmutableAudience.FlushQueueToDiskForTesting();
907+
908+
var files = ReadQueueFiles();
909+
Assert.IsTrue(files.Any(c => c.Contains("\"session_start\"")),
910+
"Reset must fire session_start for the new session");
911+
Assert.IsFalse(files.Any(c => c.Contains("\"session_end\"")),
912+
"Reset must not leak session_end for the old session (Web SDK parity)");
913+
914+
var secondAnonymousId = Identity.Get(_testDir);
915+
Assert.IsNotNull(secondAnonymousId, "Reset should have minted a fresh anonymousId");
916+
Assert.AreNotEqual(firstAnonymousId, secondAnonymousId,
917+
"Reset must mint a new anonymousId");
918+
919+
ImmutableAudience.Shutdown();
920+
}
921+
922+
[Test]
923+
public void Reset_ConsentNone_DoesNotStartSession()
924+
{
925+
// At consent=None there is no session running; Reset must not
926+
// spin one up (Web SDK reset() guards on !isTrackingDisabled()).
927+
ImmutableAudience.Init(MakeConfig(ConsentLevel.None));
928+
929+
ImmutableAudience.Reset();
930+
ImmutableAudience.Shutdown();
931+
932+
Assert.IsFalse(ReadQueueFiles().Any(c => c.Contains("\"session_start\"")),
933+
"Reset at consent=None must not fire session_start");
934+
}
935+
885936
[Test]
886937
public void SetConsent_AnonymousToNone_DoesNotEmitSessionEnd()
887938
{

0 commit comments

Comments
 (0)