fix(battle-node): collision-safe battle-id registration + viewer eviction

RegisterPending → TryRegisterPending (TryAdd instead of indexer) so
battle-id collisions return false instead of silently evicting a live
battle. MatchingBridge retries with fresh IDs on collision (max 5).

Before registering, EvictStaleForViewer removes any stale pending
battle the viewer left behind, enforcing the one-pending-per-viewer
invariant that was previously comment-asserted.

Store tests switched to per-test local stores to fix a race under
the assembly-wide ParallelScope.All.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-06-04 22:13:20 -04:00
parent c6fb411861
commit 564b1d678f
5 changed files with 60 additions and 27 deletions

View File

@@ -6,8 +6,8 @@ public sealed class InMemoryBattleSessionStore : IBattleSessionStore
{
private readonly ConcurrentDictionary<string, PendingBattle> _pending = new();
public void RegisterPending(PendingBattle battle) =>
_pending[battle.BattleId] = battle;
public bool TryRegisterPending(PendingBattle battle) =>
_pending.TryAdd(battle.BattleId, battle);
public PendingBattle? TryGetPending(string battleId) =>
_pending.TryGetValue(battleId, out var b) ? b : null;