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
+1 -10
View File
@@ -7,7 +7,7 @@ from types import SimpleNamespace
import pytest
from unshackle.core.constants import DOWNLOAD_CANCELLED
from unshackle.core.downloaders.requests import TokenBucket, format_speed, parse_speed_limit, set_speed_limit
from unshackle.core.downloaders.requests import TokenBucket, format_speed, parse_speed_limit
requests_downloader = importlib.import_module("unshackle.core.downloaders.requests")
@@ -119,15 +119,6 @@ def test_bucket_chunk_larger_than_capacity_does_not_deadlock(monkeypatch):
assert 1.0 < waits[0] < 2.0
def test_locked_limit_ignores_unlocked_calls():
"""serve's global_speed_limit must survive the per-job set in dl.result()."""
set_speed_limit(5_000_000, lock=True)
set_speed_limit(None)
set_speed_limit(1_000_000)
limiter = requests_downloader.speed_limiter
assert limiter is not None and limiter.rate == 5_000_000
def test_bucket_wait_aborts_on_cancellation():
"""Debt sleeps grow with thread count; cancelling must not wait them out."""
bucket = TokenBucket(1_000)