fix(execution): cancel SQL nullable type error, KIS child cancel detection, worker exception logging
Co-authored-by: genichin <4282227+genichin@users.noreply.github.com>
This commit is contained in:
co-authored by
genichin
parent
2b412fd786
commit
f0ac909958
@@ -179,3 +179,49 @@ def test_operator_cancel_is_sent_once_across_repeat_and_restart():
|
||||
assert restarted.cancel_pending_slot(sid) == "cancel_already_recorded"
|
||||
assert broker.cancel_calls == 1
|
||||
assert repo.fetch_slot(sid).cancel_state == CancelState.REQUESTED.value
|
||||
|
||||
|
||||
# ── Regression: first-cancel reservation (retry_before=None) ─────────────────
|
||||
|
||||
def test_first_cancel_reservation_with_no_retry_before_succeeds():
|
||||
"""First cancel reservation with retry_before=None must reserve exactly once (fix for
|
||||
PostgreSQL IndeterminateDatatype; the in-memory repo mirrors the corrected SQL path)."""
|
||||
broker = ProgrammableBroker()
|
||||
repo, svc, intents, execution, _, _ = _wire(broker)
|
||||
sid = _buy_to_holding(intents, execution)
|
||||
intents.submit_sell(SellIntent(intent_id="s1", slot_id=sid))
|
||||
broker.responder = lambda side: FillStatus(state="accepted")
|
||||
execution.run_once() # dispatch
|
||||
|
||||
# First operator cancel — retry_before=None path
|
||||
result = execution.cancel_pending_slot(sid)
|
||||
assert result == "ok", f"expected ok, got {result}"
|
||||
assert broker.cancel_calls == 1
|
||||
# Second call must be idempotent (cancel_state already set)
|
||||
result2 = execution.cancel_pending_slot(sid)
|
||||
assert result2 == "cancel_already_recorded"
|
||||
assert broker.cancel_calls == 1 # no second broker call
|
||||
|
||||
|
||||
def test_timeout_cancel_first_attempt_with_retry_before_none():
|
||||
"""Timeout cancel's first attempt passes retry_before=None; must call broker once."""
|
||||
broker = ProgrammableBroker()
|
||||
repo, svc, intents, execution, _, _ = _wire(broker)
|
||||
sid = _buy_to_holding(intents, execution)
|
||||
intents.submit_sell(SellIntent(intent_id="s1", slot_id=sid))
|
||||
broker.responder = lambda side: FillStatus(
|
||||
state="accepted",
|
||||
raw={"order_open_confirmed": True},
|
||||
)
|
||||
execution.run_once() # dispatch
|
||||
|
||||
# Simulate timeout: set order_submitted_at well in the past
|
||||
s = repo.fetch_slot(sid)
|
||||
repo._slots[sid] = replace(
|
||||
s,
|
||||
order_submitted_at=datetime.now(tz=timezone.utc) - timedelta(seconds=120),
|
||||
order_date="20260901",
|
||||
timeout_sec=30,
|
||||
)
|
||||
execution.run_once() # should trigger timeout cancel
|
||||
assert broker.cancel_calls == 1
|
||||
|
||||
Reference in New Issue
Block a user