Ottimizza controllo stabilita file in batch

This commit is contained in:
2026-08-13 10:02:03 +02:00
parent 6b356e8983
commit 6fa96f8abe
4 changed files with 152 additions and 30 deletions

View File

@@ -10,6 +10,7 @@ from bakrest.backup import (
_run_command,
_run_robocopy,
_split_existing_files,
_split_stable_files,
)
from bakrest.config import parse_config
from bakrest.registry import ChangeEvent, ChangeRegistry
@@ -161,6 +162,51 @@ def test_robocopy_marks_each_file_copied_after_all_destinations(
assert pending_counts_after_commands == [2, 2, 1, 1]
def test_stability_check_waits_per_batch_not_per_file(tmp_path: Path, monkeypatch) -> None:
source = tmp_path / "Lavori"
source.mkdir()
files = []
for index in range(3):
path = source / f"file-{index}.docx"
path.write_text("ok", encoding="utf-8")
files.append(path)
config = parse_config(
{
"watch": {
"include_dirs": [str(source)],
"include_extensions": [".docx"],
"exclude_dirs": [],
"exclude_patterns": [],
},
"backup": {
"engine": "robocopy",
"remote_destinations": ["\\\\server\\Backup1"],
"server_check": {"type": "tcp", "port": 445, "interval_seconds": 1800, "timeout_seconds": 1},
},
"stability": {
"min_age_seconds": 0,
"unchanged_check_interval_seconds": 5,
"unchanged_checks_required": 2,
},
},
tmp_path / "config.toml",
)
events = [ChangeEvent(path=str(path), event_type="modified") for path in files]
sleeps: list[int] = []
def fake_sleep(seconds):
sleeps.append(seconds)
monkeypatch.setattr("bakrest.backup.time.sleep", fake_sleep)
stable, unstable = _split_stable_files(events, config, _NullLogger())
assert [event.path for event in stable] == [str(path) for path in files]
assert unstable == []
assert sleeps == [5, 5]
class _NullLogger:
def info(self, *args, **kwargs) -> None:
pass

View File

@@ -27,5 +27,6 @@ def test_notifier_task_runs_every_30_minutes() -> None:
def test_backup_task_uses_logoff_event_and_nogui_backup() -> None:
xml = (Path("tasks") / "BakRestBackupOnLogoff.xml").read_text(encoding="utf-8")
assert "EventID=4647" in xml
assert "Microsoft-Windows-Winlogon" in xml
assert "EventID=7002" in xml
assert "-m bakrest.tray_app --nogui" in xml