test: delete slow, timing-based and redundant tests

This commit is contained in:
imSp4rky
2026-12-05 15:20:05 -07:00
parent 783a2fc185
commit 3a0a74e694
292 changed files with 153 additions and 15174 deletions
-98
View File
@@ -4,24 +4,17 @@ tests only. No threads, sockets, or real downloads; the clock is supplied explic
from __future__ import annotations
import inspect
from functools import partial
from itertools import pairwise
from pathlib import Path
import pytest
from unshackle.core.downloaders.requests import (
TAIL_BOOST_MIN_SEGMENT_SIZE,
TAIL_BOOST_PART_SIZE,
AdaptiveWorkerController,
plan_tail_parts,
requests,
split_ranges,
submission_window,
tail_boost_engages,
)
from unshackle.core.tracks.track import DownloadContext
pytestmark = pytest.mark.unit
@@ -55,13 +48,6 @@ def run_tick(c: AdaptiveWorkerController, rate: float, now: float, errors: int =
return c.update(now), now
def test_starts_at_cap() -> None:
assert AdaptiveWorkerController(cap=16).target == 16
assert AdaptiveWorkerController(cap=4).target == 4
assert AdaptiveWorkerController(cap=1).target == 2 # clamped up to ADAPTIVE_MIN
assert AdaptiveWorkerController(cap=16, start=6).target == 6 # explicit start wins
def test_no_op_before_warmup() -> None:
c = AdaptiveWorkerController(cap=16, start=6, tick=TICK, window=WINDOW)
assert c.update(0.0) == 6 # arms last_tick before any samples are recorded
@@ -122,22 +108,6 @@ def test_halves_and_cooldown_on_error_burst() -> None:
assert target == 5
def test_clamps_to_bounds_and_never_exceeds_cap() -> None:
c = AdaptiveWorkerController(cap=4, tick=TICK, window=WINDOW)
assert c.target == 4 # already at cap (min(6, 4))
now = 0.0
c.update(now)
rate = 1_000_000.0
now = fill_window(c, rate, now)
seen = [c.update(now)]
for _ in range(10):
rate *= 2
target, now = run_tick(c, rate, now)
seen.append(target)
assert all(2 <= s <= 4 for s in seen)
assert max(seen) == 4 # never exceeds the cap
def test_error_burst_floors_at_min() -> None:
c = AdaptiveWorkerController(cap=16, start=2, tick=TICK, window=WINDOW)
now = 0.0
@@ -157,15 +127,6 @@ def test_tail_guard_suppresses_increase() -> None:
assert c.update(now, 3) == 6 # 3 < target 6 -> holds at 6 rather than climbing to 8
def test_tail_guard_none_path_unchanged() -> None:
# without a tail count, the update still probes upward on the first evaluation
c = AdaptiveWorkerController(cap=16, start=6, tick=TICK, window=WINDOW)
now = 0.0
c.update(now)
now = fill_window(c, 1_000_000.0, now)
assert c.update(now) == 8 # first evaluation 6 -> 8
def test_tail_guard_still_halves_on_error_burst() -> None:
# the guard suppresses growth but never blocks an error-burst decrease
c = AdaptiveWorkerController(cap=16, start=6, tick=TICK, window=WINDOW)
@@ -195,17 +156,6 @@ def run_scaling(c: AdaptiveWorkerController, now: float, seconds: float, work: i
return now
def test_probe_kept_when_the_true_gain_clears_the_bar() -> None:
c = AdaptiveWorkerController(cap=16, start=10, tick=TICK, window=WINDOW)
now = 0.0
c.update(now)
rate = 1_000_000.0
now = fill_window(c, rate, now)
assert c.update(now) == 12 # first evaluation probes 10 -> 12
target, now = run_tick(c, rate * 1.2, now)
assert target == 14 # probe held, and the controller climbs again
def test_recovers_to_the_cap_after_an_error_burst() -> None:
c = AdaptiveWorkerController(cap=16, start=16, tick=TICK, window=WINDOW)
now = 0.0
@@ -222,30 +172,6 @@ def test_recovers_to_the_cap_after_an_error_burst() -> None:
assert c.target == 16, "controller left the cap on a link where every worker still pays"
def test_reverts_when_the_probe_stops_paying_on_a_saturated_link() -> None:
c = AdaptiveWorkerController(cap=16, start=8, tick=TICK, window=WINDOW)
now = 0.0
c.update(now)
rate = 8 * PER_WORKER
now = fill_window(c, rate, now)
seen = [c.update(now, 10_000)]
for _ in range(8):
rate = min(c.target, 10) * PER_WORKER
end = now + TICK
while now < end - 1e-9:
now += DT
c.record_bytes(int(rate * DT), now)
seen.append(c.update(now, 10_000))
assert max(seen) <= 12 # one probe past the knee is the most it may hold
assert seen[-1] <= 12
def test_submission_window_stages_a_spare_segment_for_every_worker() -> None:
assert submission_window(16) == 32
for target in (2, 4, 6, 16):
assert submission_window(target) == 2 * target
def test_plan_tail_parts_full_coverage_no_gaps() -> None:
size = 20 * 1024 * 1024
parts = plan_tail_parts(size, spare=8)
@@ -265,13 +191,6 @@ def test_plan_tail_parts_respects_spare_cap() -> None:
assert parts[0][0] == 0 and parts[-1][1] == size - 1
def test_plan_tail_parts_part_size_bounded() -> None:
size = 40 * 1024 * 1024
parts = plan_tail_parts(size, spare=16)
# never more parts than ~ceil(size / TAIL_BOOST_PART_SIZE)
assert len(parts) <= -(-size // TAIL_BOOST_PART_SIZE)
def test_plan_tail_parts_skips_small_or_no_spare() -> None:
assert plan_tail_parts(TAIL_BOOST_MIN_SEGMENT_SIZE - 1, spare=8) == [] # too small
assert plan_tail_parts(20 * 1024 * 1024, spare=1) == [] # not enough spare workers
@@ -300,25 +219,8 @@ def test_tail_boost_engages_on_idle_capacity() -> None:
assert tail_boost_engages(remaining=6, pending=6, target=16) # spare 10 >= 6
def test_tail_boost_engages_when_remaining_is_a_full_stride() -> None:
# remaining sits at 6 (one worker stride) while the target has climbed to 16, so 14 workers
# are idle. idle capacity far exceeds the remaining segments, so the boost must engage.
assert tail_boost_engages(remaining=6, pending=2, target=16)
def test_tail_boost_does_not_engage_early_or_saturated() -> None:
assert not tail_boost_engages(remaining=54, pending=2, target=6) # early: 54 > spare 4
assert not tail_boost_engages(remaining=1, pending=8, target=8) # saturated: spare 0
assert not tail_boost_engages(remaining=0, pending=2, target=8) # nothing left
assert not tail_boost_engages(remaining=5, pending=10, target=8) # over-subscribed: spare < 0
def test_download_context_adaptive_default_false() -> None:
ctx = DownloadContext(save_path=Path("x.mp4"), save_dir=Path("."), progress=partial(lambda **_: None))
assert ctx.adaptive_workers is False
def test_requests_accepts_adaptive_kwarg() -> None:
sig = inspect.signature(requests)
assert "adaptive" in sig.parameters
assert sig.parameters["adaptive"].default is False