test(engine-ambient): TestBattleScope + HeadlessFixture split for multi-instance
Step 6 of multi-instancing migration. HeadlessEngineEnv.EnsureInitialized is split into EnsureProcessGlobals (idempotent, process-once) + SeedCharaIdsOnCurrentAmbient (per-test). New TestBattleScope IDisposable sets up a fresh BattleAmbientContext per test. NonParallelizable removed from converted classes; assembly-level Parallelizable(Fixtures) enabled. SVSim.BattleEngine.Tests fully green under parallel test execution. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -16,21 +16,29 @@ namespace SVSim.BattleEngine.Tests
|
||||
[TestFixture]
|
||||
public class RandomDrawOracleTests
|
||||
{
|
||||
private TestBattleScope _scope;
|
||||
|
||||
[SetUp] public void SetUpScope() { _scope = new TestBattleScope(); }
|
||||
|
||||
[TearDown]
|
||||
public void ResetRandomDrawGate()
|
||||
{
|
||||
// NewAuthoritativeBattle sets the process-global BattleManagerBase.IsRandomDraw = true; reset it
|
||||
// so this fixture doesn't leak that state into later-running fixtures (which expect the default
|
||||
// false / top-of-deck draw behavior). Prevents order-dependent flakes as more RNG oracles land.
|
||||
// (Now an ambient write inside the scope; harmless either way.)
|
||||
BattleManagerBase.IsRandomDraw = false;
|
||||
_scope?.Dispose();
|
||||
_scope = null;
|
||||
}
|
||||
|
||||
// Draw with a single scripted unit; return (drawnCardId, deckCountAfter). The deck is seeded with
|
||||
// three distinguishable cards at indices 2,3,4 -> Index-order positions 0,1,2 map to
|
||||
// RngDeckCardA/B/C. The draw makes one StableRandom(3) call -> index = floor(3*unit).
|
||||
private static (int drawnId, int deckAfter) DrawWith(double unit)
|
||||
private (int drawnId, int deckAfter) DrawWith(double unit)
|
||||
{
|
||||
var mgr = HeadlessEngineEnv.NewAuthoritativeBattle(new ScriptedRandomSource(new[] { unit }));
|
||||
_scope.Ctx.Mgr = mgr;
|
||||
var player = mgr.BattlePlayer;
|
||||
|
||||
HeadlessEngineEnv.SeedDeck(mgr, HeadlessEngineEnv.RngDeckCardA, index: 2, isPlayer: true);
|
||||
|
||||
Reference in New Issue
Block a user