Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions tests/test_timeout.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

from .common import TestCase, fate_suite

PORT = 8002
CONTENT = open(fate_suite("mpeg2/mpeg2_field_encoding.ts"), "rb").read()
# Needs to be long enough for all host OSes to deal.
TIMEOUT = 0.25
Expand All @@ -34,8 +33,17 @@ def log_message(self, format: object, *args: object) -> None:


class TestTimeout(TestCase):
port = 8002

def setUp(cls) -> None:
cls._server = HttpServer(("", PORT), SlowRequestHandler)
while True:
try:
cls._server = HttpServer(("", cls.port), SlowRequestHandler)
except OSError:
cls.port += 1
else:
break

cls._thread = threading.Thread(target=cls._server.handle_request)
cls._thread.daemon = True # Make sure the tests will exit.
cls._thread.start()
Expand All @@ -46,14 +54,16 @@ def tearDown(cls) -> None:

def test_no_timeout(self) -> None:
start = time.time()
av.open(f"http://localhost:{PORT}/mpeg2_field_encoding.ts")
av.open(f"http://localhost:{self.port}/mpeg2_field_encoding.ts")
duration = time.time() - start
assert duration > DELAY

def test_open_timeout(self) -> None:
with self.assertRaises(av.ExitError):
start = time.time()
av.open(f"http://localhost:{PORT}/mpeg2_field_encoding.ts", timeout=TIMEOUT)
av.open(
f"http://localhost:{self.port}/mpeg2_field_encoding.ts", timeout=TIMEOUT
)

duration = time.time() - start
assert duration < DELAY
Expand All @@ -62,7 +72,7 @@ def test_open_timeout_2(self) -> None:
with self.assertRaises(av.ExitError):
start = time.time()
av.open(
f"http://localhost:{PORT}/mpeg2_field_encoding.ts",
f"http://localhost:{self.port}/mpeg2_field_encoding.ts",
timeout=(TIMEOUT, None),
)

Expand Down
Loading