refactor(fudai): 拆出首次运行清空预约队列块(2783→2661,-122 行)
把 run_once_basic 中"首次运行清空预约队列与写空状态文件"的 130 行块抽到 fudai_run_blocks.maybe_clear_reservation_queue_on_first_run: - 首次运行:清空 reservations / 写空状态文件 / 标记 _first_run_once_basic=False - 非首次:仅记录日志保持当前队列 新增 4 个单元测试覆盖:首次清空 / 非首次保持 / 无 state_path 兜底 / 日志异常吞噬。 1123 → 1127 用例全过。 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
e6da24c2a6
commit
41fc4ecbe0
3 files changed
+162
-123
No files matched your search
@@ -423,3 +423,45 @@ def test_screenshot_get_screenshot_exception_treated_as_false():
|
||||
a.operation.get_screenshot.side_effect = RuntimeError("adb fail")
|
||||
ok, _ = fudai_run_blocks.take_screenshot_with_retries(a, time.time(), max_retries=2)
|
||||
assert ok is False
|
||||
|
||||
|
||||
# ---- maybe_clear_reservation_queue_on_first_run ---- #
|
||||
|
||||
def test_clear_queue_first_run_clears_reservations():
|
||||
a = MagicMock()
|
||||
a._first_run_once_basic = True
|
||||
a.reservations = [{"future_ts": 100}, {"future_ts": 200}]
|
||||
a._reservations_state_path = None # 跳过 write 状态文件
|
||||
fudai_run_blocks.maybe_clear_reservation_queue_on_first_run(a)
|
||||
assert a.reservations == []
|
||||
assert a._first_run_once_basic is False
|
||||
|
||||
|
||||
def test_clear_queue_non_first_run_keeps_reservations():
|
||||
a = MagicMock()
|
||||
a._first_run_once_basic = False
|
||||
original = [{"future_ts": 100}]
|
||||
a.reservations = original
|
||||
fudai_run_blocks.maybe_clear_reservation_queue_on_first_run(a)
|
||||
# 队列保持
|
||||
assert a.reservations is original
|
||||
|
||||
|
||||
def test_clear_queue_first_run_no_state_path_still_clears():
|
||||
a = MagicMock()
|
||||
a._first_run_once_basic = True
|
||||
a.reservations = [{"future_ts": 100}]
|
||||
a._reservations_state_path = None
|
||||
fudai_run_blocks.maybe_clear_reservation_queue_on_first_run(a)
|
||||
assert a.reservations == []
|
||||
|
||||
|
||||
def test_clear_queue_swallows_log_exceptions():
|
||||
a = MagicMock()
|
||||
a._first_run_once_basic = True
|
||||
a.reservations = [{"future_ts": 100}]
|
||||
a._log_kv.side_effect = RuntimeError("boom")
|
||||
a._reservations_state_path = None
|
||||
# 应不抛错
|
||||
fudai_run_blocks.maybe_clear_reservation_queue_on_first_run(a)
|
||||
assert a.reservations == []
|
||||
Reference in new issue
Block a user