mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-12-05 07:25:08 +00:00
refactor(downloader): make dl.result the one writer of the speed limit and drop speed_limit_locked
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user