refactor(reservation): 拆出 attend_window 等待开奖检查 + 锁定期晋升(1375→1309,-66 行)
- check_waiting_for_reservation_lottery:等待预约福袋开奖时不抢占其他预约 - maybe_promote_locked_reservation:锁定期内把锁定预约移到队头, 若已不在队列则清除锁定期 新增 8 个单元测试,1248 → 1256 用例全过。 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
b8a35656a0
commit
e9e8e322c6
3 files changed
+206
-80
No files matched your search
@@ -149,3 +149,98 @@ def test_log_attend_window_check_details_swallows_exceptions():
|
||||
bad, now_ts=0, focus_until=0, ft=0, dynamic_ahead=0,
|
||||
join_ahead=0.0, poll_before=0.0, est_back_times=0,
|
||||
)
|
||||
|
||||
|
||||
# ---- check_waiting_for_reservation_lottery ---- #
|
||||
|
||||
def test_waiting_lottery_with_reservation_returns_true():
|
||||
a = MagicMock()
|
||||
a._waiting_for_lottery_result = True
|
||||
a._current_attending_reservation_fudai = True
|
||||
assert h.check_waiting_for_reservation_lottery(a) is True
|
||||
|
||||
|
||||
def test_waiting_lottery_only_one_flag_returns_false():
|
||||
a = MagicMock()
|
||||
a._waiting_for_lottery_result = True
|
||||
a._current_attending_reservation_fudai = False
|
||||
assert h.check_waiting_for_reservation_lottery(a) is False
|
||||
|
||||
a._waiting_for_lottery_result = False
|
||||
a._current_attending_reservation_fudai = True
|
||||
assert h.check_waiting_for_reservation_lottery(a) is False
|
||||
|
||||
|
||||
def test_waiting_lottery_neither_flag_returns_false():
|
||||
a = MagicMock()
|
||||
a._waiting_for_lottery_result = False
|
||||
a._current_attending_reservation_fudai = False
|
||||
assert h.check_waiting_for_reservation_lottery(a) is False
|
||||
|
||||
|
||||
# ---- maybe_promote_locked_reservation ---- #
|
||||
|
||||
def test_promote_locked_no_lock_period_returns_unchanged():
|
||||
a = MagicMock()
|
||||
reservations = [{"future_ts": 100}]
|
||||
ref = [0.0]
|
||||
result = h.maybe_promote_locked_reservation(
|
||||
a, reservations, ref, focus_until=0.0, now_ts=200.0, poll_before=10.0
|
||||
)
|
||||
assert result == 0.0
|
||||
|
||||
|
||||
def test_promote_locked_expired_returns_unchanged():
|
||||
"""now_ts >= focus_until → 锁定期已过,不修改"""
|
||||
a = MagicMock()
|
||||
reservations = [{"future_ts": 100}]
|
||||
ref = [50.0]
|
||||
result = h.maybe_promote_locked_reservation(
|
||||
a, reservations, ref, focus_until=50.0, now_ts=100.0, poll_before=10.0
|
||||
)
|
||||
assert result == 50.0
|
||||
|
||||
|
||||
def test_promote_locked_target_not_in_queue_clears_focus():
|
||||
"""锁定期对应的预约已不在队列 → 清除锁定期"""
|
||||
a = MagicMock()
|
||||
reservations = [{"future_ts": 200}, {"future_ts": 300}]
|
||||
# focus_until = 1000,但队列里没有 ft+10 = 1000 的预约
|
||||
ref = [1000.0]
|
||||
now = 500.0
|
||||
result = h.maybe_promote_locked_reservation(
|
||||
a, reservations, ref, focus_until=1000.0, now_ts=now, poll_before=10.0
|
||||
)
|
||||
assert result == 0.0
|
||||
assert ref[0] == 0.0
|
||||
|
||||
|
||||
def test_promote_locked_already_at_head_no_swap():
|
||||
"""锁定预约已在队头 → 不调整顺序"""
|
||||
a = MagicMock()
|
||||
# focus_until = 200 + 10 = 210,正好是第一个预约的"预期 focus"
|
||||
reservations = [{"future_ts": 200}, {"future_ts": 300}]
|
||||
ref = [210.0]
|
||||
result = h.maybe_promote_locked_reservation(
|
||||
a, reservations, ref, focus_until=210.0, now_ts=100.0, poll_before=10.0
|
||||
)
|
||||
assert result == 210.0
|
||||
# 顺序未变
|
||||
assert reservations[0]["future_ts"] == 200
|
||||
|
||||
|
||||
def test_promote_locked_swaps_to_head():
|
||||
"""锁定预约不在队头 → 移到队头"""
|
||||
a = MagicMock()
|
||||
# focus_until = 300 + 10 = 310,对应队列中第二个预约
|
||||
reservations = [
|
||||
{"future_ts": 200},
|
||||
{"future_ts": 300},
|
||||
]
|
||||
ref = [310.0]
|
||||
result = h.maybe_promote_locked_reservation(
|
||||
a, reservations, ref, focus_until=310.0, now_ts=100.0, poll_before=10.0
|
||||
)
|
||||
assert result == 310.0
|
||||
# 锁定预约(300)已被移到队头
|
||||
assert reservations[0]["future_ts"] == 300
|
||||
Reference in new issue
Block a user