fix: 编号进度改为单线程写入并在任务上显示原因
This commit is contained in:
@@ -4,6 +4,7 @@ from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
import threading
|
||||
from pathlib import Path
|
||||
|
||||
import httpx
|
||||
@@ -346,6 +347,46 @@ def test_spool_keeps_downloading_when_meta_replace_is_denied(monkeypatch, tmp_pa
|
||||
assert sleeps
|
||||
|
||||
|
||||
def test_spool_writer_serves_flush_and_read_together(tmp_path: Path):
|
||||
spool = IdSpool(tmp_path)
|
||||
spool.open()
|
||||
errors: list[BaseException] = []
|
||||
found: list[str] = []
|
||||
|
||||
def produce() -> None:
|
||||
try:
|
||||
for index in range(300):
|
||||
spool.add(str(index))
|
||||
if index % 40 == 0:
|
||||
spool.flush()
|
||||
IdSpool.listing_finished(tmp_path)
|
||||
spool.mark_complete()
|
||||
except BaseException as exc:
|
||||
errors.append(exc)
|
||||
|
||||
def consume() -> None:
|
||||
try:
|
||||
while len(found) < 300:
|
||||
found.extend(spool.pull())
|
||||
if spool.caught_up() and len(found) < 300:
|
||||
break
|
||||
except BaseException as exc:
|
||||
errors.append(exc)
|
||||
|
||||
try:
|
||||
writer = threading.Thread(target=produce)
|
||||
reader = threading.Thread(target=consume)
|
||||
writer.start()
|
||||
reader.start()
|
||||
writer.join()
|
||||
reader.join()
|
||||
assert errors == []
|
||||
assert found == [str(index) for index in range(300)]
|
||||
assert spool.caught_up() is True
|
||||
finally:
|
||||
spool.close()
|
||||
|
||||
|
||||
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"])
|
||||
@@ -685,7 +726,7 @@ async def _unknown_download_error_is_generic(tmp_path: Path, caplog):
|
||||
finally:
|
||||
_restore(saved)
|
||||
assert job.status == "error"
|
||||
assert job.message == "下载失败,详情见日志"
|
||||
assert job.message == "下载中断,已下载的内容还在,点继续即可"
|
||||
assert "socket exploded" in caplog.text
|
||||
assert "socket exploded" not in job.message
|
||||
|
||||
|
||||
Reference in New Issue
Block a user