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:
@@ -2,10 +2,8 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import copy
|
||||
import importlib
|
||||
import json
|
||||
import logging
|
||||
import re
|
||||
import threading
|
||||
from collections.abc import Iterator
|
||||
@@ -14,7 +12,6 @@ from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
from typing import Any
|
||||
|
||||
import m3u8
|
||||
import pytest
|
||||
import requests as rq
|
||||
from requests.adapters import HTTPAdapter
|
||||
@@ -22,13 +19,12 @@ from urllib3.util.retry import Retry
|
||||
|
||||
from unshackle.core import service as service_module
|
||||
from unshackle.core import session as http_session
|
||||
from unshackle.core.config import Config, config
|
||||
from unshackle.core.manifests import DASH, HLS
|
||||
from unshackle.core.config import config
|
||||
from unshackle.core.manifests import DASH
|
||||
from unshackle.core.service import Service
|
||||
from unshackle.core.session import MaxRetriesError, RecordedSession, RnetSession, record_requests, unrecorded
|
||||
from unshackle.core.tracks.track import Track
|
||||
from unshackle.core.utilities import close_debug_logger, init_debug_logger
|
||||
from unshackle.core.utils import bitrate
|
||||
from unshackle.core.utils.xml import load_xml
|
||||
|
||||
dl = importlib.import_module("unshackle.core.downloaders.requests")
|
||||
@@ -190,13 +186,6 @@ def test_a_retried_request_writes_one_entry_per_attempt(server, debug_log, make_
|
||||
assert [(e["request"]["attempt"], e["response"]["status"]) for e in entries] == [(1, 503), (2, 200)]
|
||||
|
||||
|
||||
def test_each_rnet_attempt_with_a_cut_body_names_its_failure(server, debug_log):
|
||||
with pytest.raises(MaxRetriesError):
|
||||
rnet_session().get(f"{server.url}/cut", max_retries=1)
|
||||
|
||||
assert [(e["request"]["attempt"], bool(e["failure"])) for e in records(debug_log)] == [(1, True), (2, True)]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("make_session", "kwargs", "error"),
|
||||
[
|
||||
@@ -262,22 +251,6 @@ def test_a_debug_run_without_debug_requests_records_nothing(
|
||||
assert "session_start" in debug_log.read_text(encoding="utf-8")
|
||||
|
||||
|
||||
def test_record_requests_leaves_the_session_alone_without_debug_requests(monkeypatch):
|
||||
monkeypatch.setattr(config, "debug_requests", False)
|
||||
session = rq.Session()
|
||||
record_requests(session)
|
||||
|
||||
assert type(session) is rq.Session
|
||||
|
||||
|
||||
def test_a_recorded_adapter_reads_through_and_copies(debug_log):
|
||||
session = requests_session()
|
||||
adapter = session.get_adapter("http://h")
|
||||
|
||||
assert adapter.max_retries.total == 2
|
||||
assert copy.copy(adapter).max_retries.total == 2
|
||||
|
||||
|
||||
def test_the_service_session_records_only_with_debug_requests(monkeypatch):
|
||||
class Stop(Exception):
|
||||
pass
|
||||
@@ -298,14 +271,6 @@ def test_the_service_session_records_only_with_debug_requests(monkeypatch):
|
||||
JWT = "eyJhbGciOi.eyJzdWIi.c2ln"
|
||||
|
||||
|
||||
def test_the_rnet_console_line_keeps_the_query(server, debug_log, caplog):
|
||||
with caplog.at_level("DEBUG"):
|
||||
rnet_session().get(f"{server.url}/{JWT}/pts_0.mp4?sig=S2")
|
||||
|
||||
(line,) = [r.getMessage() for r in caplog.records if " 200 " in r.getMessage()]
|
||||
assert f'"GET /{JWT}/pts_0.mp4?sig=S2 ' in line
|
||||
|
||||
|
||||
def body_of(
|
||||
server: Server, debug_log: Path, make_session: Any, path: str, kind: str | None, doc: str | bytes, **kw: Any
|
||||
) -> tuple[str, bytes] | None:
|
||||
@@ -425,15 +390,6 @@ def test_a_hostile_path_stays_inside_the_folder(server, debug_log, tmp_path, mak
|
||||
assert sorted(e["response"]["body_file"] for e in records(debug_log)) == sorted(names)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("make_session", SESSIONS)
|
||||
def test_the_size_comes_from_the_body_without_a_content_length(server, debug_log, make_session):
|
||||
server.docs["/chunked"] = '{"a": 1}'
|
||||
server.types["/chunked"] = "application/json"
|
||||
make_session().get(f"{server.url}/chunked")
|
||||
|
||||
assert records(debug_log)[-1]["response"]["size"] == len(server.docs["/chunked"])
|
||||
|
||||
|
||||
@pytest.mark.parametrize("make_session", SESSIONS)
|
||||
def test_a_recorded_body_stays_readable_by_the_caller(server, debug_log, make_session):
|
||||
server.docs["/api/read"] = '{"a": 1}'
|
||||
@@ -472,11 +428,6 @@ def test_a_failed_body_read_is_recorded_and_raised_again(debug_log):
|
||||
assert entry["response"]["body_error"].startswith("ChunkedEncodingError")
|
||||
|
||||
|
||||
@pytest.mark.parametrize(("value", "limit"), [(None, 0), ("5", 5), (-5, 0)])
|
||||
def test_the_body_limit_is_a_byte_count(value, limit):
|
||||
assert Config(debug_requests_body_limit=value).debug_requests_body_limit == limit
|
||||
|
||||
|
||||
def serve_starts(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
|
||||
from aiohttp import web
|
||||
from click.testing import CliRunner
|
||||
@@ -511,41 +462,10 @@ def test_a_server_process_records_no_body(server, debug_log, monkeypatch, tmp_pa
|
||||
assert not folder(debug_log).exists()
|
||||
|
||||
|
||||
def test_serve_keeps_request_lines_out_of_the_dashboard_log(monkeypatch, tmp_path, caplog):
|
||||
from unshackle.core.api.stats import ring
|
||||
|
||||
serve_starts(monkeypatch, tmp_path)
|
||||
with caplog.at_level(logging.DEBUG):
|
||||
for name in ("RnetSession", "urllib3.connectionpool", "EXAMPLE"):
|
||||
logging.getLogger(name).debug(f"EXAMPLE {name} line ?sig=S1")
|
||||
logging.getLogger("RnetSession").warning("EXAMPLE retry warning")
|
||||
|
||||
lines = [r["msg"] for r in ring.since(0) if r["msg"].startswith("EXAMPLE")]
|
||||
assert lines == ["EXAMPLE EXAMPLE line ?sig=S1", "EXAMPLE retry warning"]
|
||||
|
||||
|
||||
def paths(path: Path) -> list[str]:
|
||||
return [e["request"]["path"] for e in records(path)]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("make_session", SESSIONS)
|
||||
def test_hls_media_probes_are_not_recorded_but_the_playlist_is(server, debug_log, make_session):
|
||||
session = make_session()
|
||||
server.docs["/v.m3u8"] = '#EXTM3U\n#EXT-X-MAP:URI="init.mp4",BYTERANGE="1@0"\n#EXTINF:4,\nseg.ts\n#EXT-X-ENDLIST\n'
|
||||
HLS.probe_ts_info(f"{server.url}/v.m3u8", session)
|
||||
playlist = m3u8.loads(server.docs["/v.m3u8"], uri=f"{server.url}/v.m3u8")
|
||||
HLS.fetch_init_section(session, playlist.segments[0].init_section, 0)
|
||||
HLS.get_track_kid_from_init(
|
||||
SimpleNamespace(get_key_id=lambda _: None), # type: ignore[arg-type]
|
||||
HLS.init_reader(playlist, session),
|
||||
playlist.segments[0].init_section,
|
||||
)
|
||||
|
||||
assert (server.hits.count("/seg.ts"), server.hits.count("/init.mp4")) == (1, 2)
|
||||
assert paths(debug_log) == ["/v.m3u8"]
|
||||
assert len(list(folder(debug_log).iterdir())) == 1
|
||||
|
||||
|
||||
@pytest.mark.parametrize("make_session", SESSIONS)
|
||||
def test_dash_init_reads_are_not_recorded_but_the_manifest_is(server, debug_log, monkeypatch, make_session):
|
||||
monkeypatch.setattr(Track, "get_key_id", lambda *_: None)
|
||||
@@ -582,28 +502,6 @@ def test_dash_init_reads_are_not_recorded_but_the_manifest_is(server, debug_log,
|
||||
assert [p.suffix for p in folder(debug_log).iterdir()] == [".mpd"]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("make_session", SESSIONS)
|
||||
def test_bitrate_probes_are_not_recorded(server, debug_log, make_session):
|
||||
session = make_session()
|
||||
bitrate.ranged_get(f"{server.url}/a.mp4", session, "bytes=0-0")
|
||||
bitrate.probe_size(bitrate.Segment(f"{server.url}/plain-b.mp4", None, None, 0.0), session)
|
||||
|
||||
assert server.hits == ["/a.mp4", "/plain-b.mp4", "/plain-b.mp4"]
|
||||
assert records(debug_log) == []
|
||||
|
||||
|
||||
@pytest.mark.parametrize("make_session", SESSIONS)
|
||||
def test_track_init_and_sample_probes_are_not_recorded(server, debug_log, make_session):
|
||||
session = make_session()
|
||||
track = Track(url=f"{server.url}/c.mp4", language="en")
|
||||
track.get_init_segment(session=session)
|
||||
track.sample_byte_range(session)
|
||||
Track(url=f"{server.url}/plain-c.mp4", language="en").get_init_segment(session=session)
|
||||
|
||||
assert (server.hits.count("/c.mp4"), server.hits.count("/plain-c.mp4")) == (4, 3)
|
||||
assert records(debug_log) == []
|
||||
|
||||
|
||||
def test_an_unrecorded_probe_keeps_the_session_attributes(server, debug_log):
|
||||
class Own(rq.Session):
|
||||
def __init__(self) -> None:
|
||||
|
||||
Reference in New Issue
Block a user