forked from kenzuya/unshackle
test(tests): make the body-retry, websocket debug-entry and gzip segment tests deterministic
This commit is contained in:
@@ -10,12 +10,16 @@ from tests.core.test_rolling_merge_hls_ism import INIT, PARTS, hls_track, make_c
|
||||
from unshackle.core.manifests import HLS
|
||||
|
||||
|
||||
def cut_gzip(part: bytes) -> bytes:
|
||||
return gzip.compress(part, mtime=0)[:-4]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"body, expected",
|
||||
[
|
||||
pytest.param(gzip.compress, lambda part: part, id="gzip"),
|
||||
pytest.param(lambda part: b"\x1f\x8b\x08" + part, lambda part: b"\x1f\x8b\x08" + part, id="gzip-magic-only"),
|
||||
pytest.param(lambda part: gzip.compress(part)[:-4], lambda part: gzip.compress(part)[:-4], id="cut-gzip"),
|
||||
pytest.param(cut_gzip, cut_gzip, id="cut-gzip"),
|
||||
],
|
||||
)
|
||||
def test_only_a_whole_gzip_segment_is_inflated(body, expected, server, tmp_path): # noqa: F811
|
||||
|
||||
@@ -34,8 +34,9 @@ def server():
|
||||
return
|
||||
with conn:
|
||||
conn.recv(65536)
|
||||
conn.sendall(plan[len(hits)] if len(hits) < len(plan) else CUT)
|
||||
reply = plan[len(hits)] if len(hits) < len(plan) else CUT
|
||||
hits.append(1)
|
||||
conn.sendall(reply)
|
||||
|
||||
threading.Thread(target=serve, daemon=True).start()
|
||||
yield f"http://127.0.0.1:{srv.getsockname()[1]}/x", plan, hits
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import re
|
||||
from collections.abc import Callable
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
@@ -106,9 +107,9 @@ async def test_each_handshake_writes_one_debug_entry(debug_log: Path) -> None:
|
||||
with pytest.raises(rnet.ConnectionError):
|
||||
await call(session.websocket, closed_port().replace("http://", "ws://", 1), GIVEN)
|
||||
|
||||
assert [
|
||||
first, refused = [
|
||||
(entry["request"]["method"], entry["response"]["status"], entry["failure"]) for entry in records(debug_log)
|
||||
] == [
|
||||
("GET", 101, None),
|
||||
("GET", None, "ConnectionError (Connection refused)"),
|
||||
]
|
||||
assert first == ("GET", 101, None)
|
||||
assert refused[:2] == ("GET", None)
|
||||
assert re.fullmatch(r"ConnectionError \([^/]+\)", refused[2])
|
||||
|
||||
Reference in New Issue
Block a user