fix(nas): bs_5m失败股尾部补扫一轮——03:0x同步链持写锁60s busy_timeout耗尽database is locked(每晚1-5只)+偶发网络错(600247),原形态=该片窗口永久小洞;修=_sweep返failed清单,run尾部(07:40+同步链早已收工)chunk/inc各自失败集各补扫一轮自愈,补扫query计入swept配额、rlr并入exit语义;+2测试(双窗口失败→双retry=6调用自愈/零失败无retry回归);venv310 644绿 [nas]
CI/CD / test (push) Successful in 29s
CI/CD / nas-deploy (push) Successful in 33s
CI/CD / nas-verify (push) Successful in 2s

This commit is contained in:
2026-08-25 21:32:28 +08:00
parent 7ad0cbea76
commit a2fe51b4b0
2 changed files with 53 additions and 5 deletions
+31
View File
@@ -267,3 +267,34 @@ def test_main_second_instance_skips(main_env, monkeypatch):
with pytest.raises(SystemExit) as e:
b5.main()
assert e.value.code == 0
def test_main_failed_stocks_retry_pass(main_env, monkeypatch):
"""失败股尾部补扫: 首扫抛错的股在 retry 轮重拉, 锁错/网络错自愈不留洞。"""
monkeypatch.setattr(sys, "argv", ["bs_5m_eod.py"])
seen = set()
def fake_process(conn, code, prefix, start, end, timeout):
key = (code, start)
first = key not in seen
seen.add(key)
if code == "600001" and first:
raise RuntimeError("database is locked")
return 48
with patch.object(b5, "_process_one", side_effect=fake_process) as m:
with pytest.raises(SystemExit) as e:
b5.main()
assert e.value.code == 0
# A 在 chunk/inc 两窗口各自首调抛错 → chunk-retry + inc-retry 各补 1 次:
# chunk(A,B) + inc(A,B) + chunk-retry(A) + inc-retry(A) = 6
assert m.call_count == 6
def test_main_retry_not_triggered_when_no_failures(main_env):
"""零失败 → 无补扫轮(回归: 原 4 次调用不变)。"""
with patch.object(b5, "_process_one", return_value=48) as m:
with pytest.raises(SystemExit) as e:
b5.main()
assert e.value.code == 0
assert m.call_count == 4 # 2 股 × (chunk+inc), 无 retry