diff options
author | coletdjnz <coletdjnz@protonmail.com> | 2024-05-18 19:12:21 +1200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-18 19:12:21 +1200 |
commit | 53b4d44f55cca66ac33dab092ef2a30b1164b684 (patch) | |
tree | 18d43f886976cc5e63bfaef1930c72f2f9cecdf0 /test/test_networking.py | |
parent | c999bac02c5a4f755b2a82488a975e91c988ffd8 (diff) |
[test] Fix connect timeout test (#9906)
Fixes https://github.com/yt-dlp/yt-dlp/issues/9659
Authored by: coletdjnz
Diffstat (limited to 'test/test_networking.py')
-rw-r--r-- | test/test_networking.py | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/test/test_networking.py b/test/test_networking.py index 994467014..d127cbb94 100644 --- a/test/test_networking.py +++ b/test/test_networking.py @@ -6,7 +6,7 @@ import sys import pytest -from yt_dlp.networking.common import Features +from yt_dlp.networking.common import Features, DEFAULT_TIMEOUT sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) @@ -523,20 +523,17 @@ class TestHTTPRequestHandler(TestRequestHandlerBase): def test_connect_timeout(self, handler): # nothing should be listening on this port connect_timeout_url = 'http://10.255.255.255' - with handler(timeout=0.01) as rh: + with handler(timeout=0.01) as rh, pytest.raises(TransportError): now = time.time() - with pytest.raises(TransportError): - validate_and_send( - rh, Request(connect_timeout_url)) - assert 0.01 <= time.time() - now < 20 + validate_and_send(rh, Request(connect_timeout_url)) + assert time.time() - now < DEFAULT_TIMEOUT - with handler() as rh: - with pytest.raises(TransportError): - # Per request timeout, should override handler timeout - now = time.time() - validate_and_send( - rh, Request(connect_timeout_url, extensions={'timeout': 0.01})) - assert 0.01 <= time.time() - now < 20 + # Per request timeout, should override handler timeout + request = Request(connect_timeout_url, extensions={'timeout': 0.01}) + with handler() as rh, pytest.raises(TransportError): + now = time.time() + validate_and_send(rh, request) + assert time.time() - now < DEFAULT_TIMEOUT def test_source_address(self, handler): source_address = f'127.0.0.{random.randint(5, 255)}' |