fix: 编号进度被拒绝访问时继续下载
This commit is contained in:
@@ -323,6 +323,29 @@ async def _server_error_is_retried(monkeypatch):
|
||||
assert waits == [1, 3, 9]
|
||||
|
||||
|
||||
def test_spool_keeps_downloading_when_meta_replace_is_denied(monkeypatch, tmp_path: Path):
|
||||
sleeps: list[float] = []
|
||||
monkeypatch.setattr(spool_module.time, "sleep", lambda seconds: sleeps.append(seconds))
|
||||
spool = IdSpool(tmp_path)
|
||||
spool.open()
|
||||
real = spool_module.os.replace
|
||||
calls = {"n": 0}
|
||||
|
||||
def flaky(src, dst):
|
||||
calls["n"] += 1
|
||||
if calls["n"] == 1:
|
||||
raise PermissionError(13, "Access is denied", str(src), 5)
|
||||
real(src, dst)
|
||||
|
||||
monkeypatch.setattr(spool_module.os, "replace", flaky)
|
||||
assert spool.add("10") is True
|
||||
spool.flush()
|
||||
assert spool.committed == 1
|
||||
assert IdSpool._peek(tmp_path)["committed"] == 1
|
||||
assert calls["n"] == 2
|
||||
assert sleeps
|
||||
|
||||
|
||||
def test_spool_dedups_ints_and_drops_uncommitted_tail(monkeypatch, tmp_path: Path):
|
||||
clock = {"now": 10.0}
|
||||
monkeypatch.setattr(spool_module.time, "monotonic", lambda: clock["now"])
|
||||
|
||||
@@ -121,7 +121,10 @@ def test_file_errors_use_chinese(tmp_path: Path, monkeypatch):
|
||||
full.winerror = 112
|
||||
full_errno = OSError("full")
|
||||
full_errno.errno = 28
|
||||
denied = OSError("denied")
|
||||
denied.winerror = 5
|
||||
assert explain_os_error(busy) == "文件被占用,请先关闭 Excel 等程序"
|
||||
assert explain_os_error(denied) == "文件被拒绝访问"
|
||||
assert explain_os_error(locked) == "文件被占用,请先关闭 Excel 等程序"
|
||||
assert explain_os_error(full) == "磁盘空间不足"
|
||||
assert explain_os_error(full_errno) == "磁盘空间不足"
|
||||
|
||||
Reference in New Issue
Block a user