feat: 校验五档等级 (ultrafast/fast/normal/slow/full) + --check-only 纯校验模式

This commit is contained in:
AskaEth committed 2026-08-22 15:31:16 +08:00
1 parent 2e505f6ea3
commit fb59000fd1
3 files changed
+278 -10

No files matched your search

+63
View File
@@ -461,3 +461,66 @@ def test_verify_recent_callback_without_progress(tmp_path):
(src / "a.txt").write_text("x")
(dst / "a.txt").write_text("x")
assert transfer.verify_recent_files(str(src), str(dst)) == []
# ---------- 校验进度 (读取量轮询) ----------
def test_read_proc_io_current_process():
"""读取 /proc/self/io 的 read_bytes"""
val = transfer.read_proc_io(os.getpid())
assert isinstance(val, int)
assert val >= 0
def test_read_proc_io_nonexistent_pid():
assert transfer.read_proc_io(99999999) == 0
def test_collect_process_tree_self():
"""自身进程无子进程时 = 自身 read_bytes"""
me = transfer.collect_process_tree_read_bytes(os.getpid())
assert isinstance(me, int) and me >= 0
def test_collect_process_tree_with_child(tmp_path):
"""进程树统计不报错, 返回合理值 (缓存命中时 read_bytes 可能为 0)"""
f = tmp_path / "data.bin"
f.write_bytes(b"x" * (4 * 1024 * 1024))
child = subprocess.Popen(["cat", str(f)], stdout=subprocess.DEVNULL,
start_new_session=True)
time.sleep(0.5)
val = transfer.collect_process_tree_read_bytes(child.pid)
child.kill(); child.wait()
assert isinstance(val, int) and val >= 0
# ---------- 校验等级 + 纯校验模式 ----------
def test_parse_check_only():
args = transfer.parse_args(["--check-only", "s", "d"])
assert args.check_only is True
def test_parse_verify_level_default():
assert transfer.parse_args(["s", "d"]).verify_level == "slow"
assert transfer.parse_args(["--check-only", "s", "d"]).verify_level == "slow"
def test_parse_verify_level_values():
for lv in ("ultrafast", "fast", "normal", "slow", "full"):
args = transfer.parse_args(["--verify-level", lv, "s", "d"])
assert args.verify_level == lv
def test_size_check_all_ok(tmp_path):
src = tmp_path / "s"; dst = tmp_path / "d"
src.mkdir(); dst.mkdir()
(src / "a.bin").write_bytes(b"x" * 1000)
(dst / "a.bin").write_bytes(b"x" * 1000)
assert transfer.size_check(str(src), str(dst)) == (0, 0)
def test_size_check_detect_diff_and_missing(tmp_path):
src = tmp_path / "s"; dst = tmp_path / "d"
src.mkdir(); dst.mkdir()
(src / "a.bin").write_bytes(b"x" * 1000)
(dst / "a.bin").write_bytes(b"x" * 999) # 大小不同
(src / "b.bin").write_bytes(b"y" * 100)
# b.bin 目标缺失
diff, miss = transfer.size_check(str(src), str(dst))
assert diff == 1 and miss == 1
def test_verify_level_order():
"""等级从快到慢的顺序固定"""
assert transfer.VERIFY_LEVELS == ["ultrafast", "fast", "normal", "slow", "full"]