refactor(downloader): make dl.result the one writer of the speed limit and drop speed_limit_locked

This commit is contained in:
imSp4rky
2026-12-04 15:11:54 -07:00
parent 491764d991
commit 8b76bb47a6
9 changed files with 88 additions and 69 deletions
+23
View File
@@ -3,6 +3,7 @@
from __future__ import annotations
import asyncio
import importlib
import logging
from pathlib import Path
@@ -12,6 +13,7 @@ from aiohttp import web
from unshackle.commands import serve as serve_cmd
from unshackle.core import config as config_module
from unshackle.core.api.download_manager import DownloadQueueManager
from unshackle.core.api.events import bus
from unshackle.core.api.handlers import dashboard_authentication
from unshackle.core.api.routes import setup_routes
@@ -20,6 +22,7 @@ from unshackle.core.config import config
pytestmark = pytest.mark.unit
LOG = logging.getLogger("serve")
requests_downloader = importlib.import_module("unshackle.core.downloaders.requests")
@pytest.fixture
@@ -131,3 +134,23 @@ def test_reload_that_adds_a_dashboard_key_needs_a_restart(
assert _reload(app) is False
assert "restart" in caplog.text and "dashboard.key" in caplog.text
assert "dashboard" not in config.serve
def test_reload_without_a_limit_leaves_the_job_limit_to_dl(running: tuple[web.Application, Path]) -> None:
app, path = running
_write(path, users={"old": {"devices": ["dev"]}})
assert _reload(app) is True
assert DownloadQueueManager(max_concurrent_downloads=2).worker_speed_limit() is None
requests_downloader.set_speed_limit(1_000_000)
limiter = requests_downloader.speed_limiter
assert limiter is not None and limiter.rate == 1_000_000
def test_reload_with_a_limit_changes_the_job_share_only(running: tuple[web.Application, Path]) -> None:
app, path = running
_write(path, users={"old": {"devices": ["dev"]}}, global_speed_limit="6M")
assert _reload(app) is True
assert DownloadQueueManager(max_concurrent_downloads=2).worker_speed_limit() == 3_000_000
assert requests_downloader.speed_limiter is None