_periodic_runtime = None monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x11d3bb0b0> @pytest.mark.unit def test_max_account_parallelism_one_keeps_sequential_semantics(_periodic_runtime, monkeypatch): """Bug 859694423a7e: setting the cap to 1 restores the old SEQUENTIAL behavior (no concurrent consults, no race surface, deterministic ordering — the semantics the test suite is pinned to). The flip counter still sees all 3 accounts.""" import time as _time monkeypatch.setattr(CEL, "roc_peak_retest_execute_enabled", lambda: True) monkeypatch.setattr("rtrader.config.settings.COMBINED_ENGINE_LIVE_ACCOUNTS", ["yuchao", "miaoyong", "cuixia"], raising=False) monkeypatch.setattr(CEL, "periodic_max_account_parallelism", lambda: 1) def _factory(acct): return CEL.LLMDecider(acct, consolidated_fn=lambda *a, **k: (_time.sleep(0.05) or {"leg": "bull", "decision": "LONG", "size_mult": 1.0, "source": "llm", "signal_source": k.get("signal_source")}), support_fn=lambda d, n: (True, {}), budget_s=2.0) events = [{"et": "10:10:00", "direction": "short"}] roc = FakeSource(ROC_LEVEL, events) db = _FakeDB() routed = [] build = lambda d, c, a: _periodic_ctx([roc]) CEL.reconcile_periodic_signal_onsets( # bootstrap DAY.isoformat(), now=datetime(2026, 7, 1, 10, 0, tzinfo=ET), execute=True, accounts=["yuchao", "miaoyong", "cuixia"], ctx_builder=build, decider_factory=_factory, flip_fn=lambda *a, **k: routed.append(k.get("signal_source")) or {"action": "flip"}, db_factory=lambda: db) out = CEL.reconcile_periodic_signal_onsets( DAY.isoformat(), now=datetime(2026, 7, 1, 10, 11, tzinfo=ET), execute=True, accounts=["yuchao", "miaoyong", "cuixia"], ctx_builder=build, decider_factory=_factory, flip_fn=lambda *a, **k: routed.append(k.get("signal_source")) or {"action": "flip"}, db_factory=lambda: db) print(f"\nDEBUG out={out} routed={routed}") for d in db[CEL.PERIODIC_SIGNAL_ROUTES].docs: print(f"DEBUG doc: acct={d.get('account_nick')} src={d.get('signal_source')} status={d.get('status')} reason={d.get('engine_reason')}") > assert out["routed"] == 3 E assert 0 == 3 tests/services/test_combined_engine_live.py:1666: AssertionError