mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-12-06 07:55:10 +00:00
test: delete slow, timing-based and redundant tests
This commit is contained in:
@@ -1,13 +1,10 @@
|
||||
import importlib
|
||||
import inspect
|
||||
import threading
|
||||
import time
|
||||
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
|
||||
from unshackle.core.downloaders.requests import TokenBucket, parse_speed_limit
|
||||
|
||||
requests_downloader = importlib.import_module("unshackle.core.downloaders.requests")
|
||||
|
||||
@@ -69,50 +66,6 @@ def test_parse_speed_limit_rejects(value):
|
||||
parse_speed_limit(value)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("rate", "expected"),
|
||||
[
|
||||
(500, "500 bytes/s"),
|
||||
(999.2, "1.0 kB/s"),
|
||||
(512_000, "512.0 kB/s"),
|
||||
(39 * 1024**2, "40.9 MB/s"),
|
||||
(1.5 * 1024**3, "1.6 GB/s"),
|
||||
],
|
||||
)
|
||||
def test_format_speed(rate, expected):
|
||||
assert format_speed(rate) == expected
|
||||
|
||||
|
||||
def test_result_accepts_a_missing_speed_limit():
|
||||
"""The API/serve path calls dl.result() by keyword without speed_limit."""
|
||||
from unshackle.commands.dl import dl
|
||||
|
||||
assert inspect.signature(dl.result).parameters["speed_limit"].default is None
|
||||
|
||||
|
||||
def test_bucket_holds_aggregate_rate_across_threads():
|
||||
rate = 10_000_000
|
||||
bucket = TokenBucket(rate)
|
||||
chunk = 100_000
|
||||
totals = [0, 0, 0, 0]
|
||||
start = time.monotonic()
|
||||
stop = start + 1.0
|
||||
|
||||
def worker(i: int) -> None:
|
||||
while time.monotonic() < stop:
|
||||
bucket.consume(chunk)
|
||||
totals[i] += chunk
|
||||
|
||||
threads = [threading.Thread(target=worker, args=(i,)) for i in range(4)]
|
||||
for t in threads:
|
||||
t.start()
|
||||
for t in threads:
|
||||
t.join()
|
||||
achieved = sum(totals) / (time.monotonic() - start)
|
||||
# exceeding the limit is a real failure; undershoot is scheduler noise on a loaded box, so no lower bound
|
||||
assert achieved <= rate * 1.1
|
||||
|
||||
|
||||
def test_bucket_refills_at_the_rate(monkeypatch):
|
||||
"""On a simulated clock the throughput is exact, so a slow refill fails like a fast one."""
|
||||
clock = [0.0]
|
||||
@@ -135,15 +88,3 @@ def test_bucket_chunk_larger_than_capacity_does_not_deadlock(monkeypatch):
|
||||
bucket.consume(1_100_000)
|
||||
assert len(waits) == 1
|
||||
assert 1.0 < waits[0] < 2.0
|
||||
|
||||
|
||||
def test_bucket_wait_aborts_on_cancellation():
|
||||
"""Debt sleeps grow with thread count; cancelling must not wait them out."""
|
||||
bucket = TokenBucket(1_000)
|
||||
DOWNLOAD_CANCELLED.set()
|
||||
try:
|
||||
start = time.monotonic()
|
||||
bucket.consume(1_000_000)
|
||||
assert time.monotonic() - start < 1.0
|
||||
finally:
|
||||
DOWNLOAD_CANCELLED.clear()
|
||||
|
||||
Reference in New Issue
Block a user