mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-12-02 05:55:08 +00:00
ci: run the unit suite in parallel and keep it off the network
Test servers shut down without the 0.5s poll wait, unit tests refuse non-loopback lookups, and three load-sensitive tests are steadied. Pushes to dev test Python 3.11 only; the docs job builds with uv.
This commit is contained in:
@@ -104,7 +104,8 @@ def test_encoded_body_is_decoded_on_disk(tmp_path, encoding_server):
|
||||
assert save_path.read_bytes() == PLAIN
|
||||
|
||||
|
||||
def test_encoded_body_discards_a_partial_instead_of_range_resuming(tmp_path, encoding_server):
|
||||
def test_encoded_body_discards_a_partial_instead_of_range_resuming(tmp_path, encoding_server, monkeypatch):
|
||||
monkeypatch.setattr(importlib.import_module("unshackle.core.downloaders.requests"), "RETRY_WAIT", 0)
|
||||
save_path = tmp_path / "sub.vtt"
|
||||
save_path.with_name("sub.vtt.!dev").write_bytes(PLAIN[:5000])
|
||||
list(download(url=encoding_server.url, save_path=save_path, session=rq.Session()))
|
||||
@@ -147,6 +148,7 @@ class _FakeRnetSession:
|
||||
def test_rnet_encoded_body_discards_a_partial_instead_of_range_resuming(tmp_path, monkeypatch):
|
||||
dl = importlib.import_module("unshackle.core.downloaders.requests")
|
||||
monkeypatch.setattr(dl, "is_rnet_session", lambda s: isinstance(s, _FakeRnetSession))
|
||||
monkeypatch.setattr(dl, "RETRY_WAIT", 0)
|
||||
session = _FakeRnetSession(PLAIN)
|
||||
save_path = tmp_path / "sub.vtt"
|
||||
save_path.with_name("sub.vtt.!dev").write_bytes(PLAIN[:5000])
|
||||
|
||||
@@ -25,7 +25,7 @@ SLOW_INDEX = 4
|
||||
FAST_BODY = b"F" * 4096
|
||||
SLOW_BODY = b"S" * 40960
|
||||
TRICKLE_CHUNK = 2048
|
||||
TRICKLE_DELAY = 0.05
|
||||
TRICKLE_DELAY = 0.5
|
||||
|
||||
|
||||
class _Handler(BaseHTTPRequestHandler):
|
||||
@@ -82,7 +82,7 @@ def test_hedge_loser_releases_handles_before_merge(tmp_path, trickle_server, mon
|
||||
slow_hits = trickle_server.counts[f"/seg/{SLOW_INDEX}"]
|
||||
assert slow_hits == 2, "hedge never fired; the race under test was not exercised"
|
||||
|
||||
# the batch must not stall draining the loser's stream (trickle alone takes ~1s)
|
||||
# the batch must not stall draining the loser's stream (trickle alone takes ~10s)
|
||||
assert wall < 5
|
||||
|
||||
for i in range(SEGMENTS):
|
||||
|
||||
@@ -91,9 +91,21 @@ def test_bucket_holds_aggregate_rate_across_threads():
|
||||
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
|
||||
# exceeding the limit is a real failure; undershoot is scheduler noise on a loaded box, so no lower bound
|
||||
assert achieved <= rate * 1.1
|
||||
assert achieved >= rate * 0.5
|
||||
|
||||
|
||||
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]
|
||||
monkeypatch.setattr(requests_downloader, "time", SimpleNamespace(monotonic=lambda: clock[0]))
|
||||
monkeypatch.setattr(
|
||||
requests_downloader, "DOWNLOAD_CANCELLED", SimpleNamespace(wait=lambda s: clock.__setitem__(0, clock[0] + s))
|
||||
)
|
||||
bucket = TokenBucket(1_000)
|
||||
for _ in range(50):
|
||||
bucket.consume(100)
|
||||
assert clock[0] == pytest.approx(5.0)
|
||||
|
||||
|
||||
def test_bucket_chunk_larger_than_capacity_does_not_deadlock(monkeypatch):
|
||||
|
||||
Reference in New Issue
Block a user