fix(dl): time elapsed lines, downloader and proxy waits with time.monotonic

This commit is contained in:
imSp4rky
2026-12-02 15:23:59 -07:00
parent ac4425cdca
commit 4afc4f7a04
6 changed files with 58 additions and 37 deletions
+21
View File
@@ -2,6 +2,8 @@
import inspect
import logging
import re
import time
from pathlib import Path
from types import SimpleNamespace
@@ -10,6 +12,7 @@ import requests
from unshackle.commands.dl import dl
from unshackle.core.config import config
from unshackle.core.console import console
from unshackle.core.constants import DOWNLOAD_CANCELLED, DOWNLOAD_LICENCE_ONLY
from unshackle.core.dl_options import DEFAULT_DOWNLOAD_PARAMS
from unshackle.core.download_archive import DownloadArchive
@@ -269,3 +272,21 @@ def test_partial_publication_of_multiple_variants_does_not_record(monkeypatch, r
run(quality=[720, 1080])
assert len(published) == 1 and published[0].exists()
assert not DownloadArchive(config.directories.cache).path.exists()
def test_wall_clock_step_back_prints_no_negative_elapsed_time(run, monkeypatch):
import unshackle.commands.dl as module
download = module.download_tracks_in_passes
wall = time.time
def download_then_step_back(*args, **kwargs):
download(*args, **kwargs)
monkeypatch.setattr(time, "time", lambda: wall() - 3)
monkeypatch.setattr(module, "download_tracks_in_passes", download_then_step_back)
with console.capture() as captured:
run()
elapsed = re.findall(r"(?:finished|downloaded|titles) in (-?[\dhms]+)", captured.get())
assert len(elapsed) == 3
assert all(re.fullmatch(r"0m\d+s", value) for value in elapsed), elapsed