d
This commit is contained in:
64
domainCheck/tests/test_register_timeout_config.py
Normal file
64
domainCheck/tests/test_register_timeout_config.py
Normal file
@@ -0,0 +1,64 @@
|
||||
import unittest
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import urllib3
|
||||
|
||||
from domainCheck.detect import register
|
||||
|
||||
|
||||
class RegisterTimeoutConfigTests(unittest.TestCase):
|
||||
def test_proxy_timeout_uses_bounded_total(self):
|
||||
with patch.dict("os.environ", {}, clear=False):
|
||||
timeout = register._resolve_register_timeout({"http": "http://127.0.0.1:8080"})
|
||||
self.assertIsInstance(timeout, urllib3.Timeout)
|
||||
self.assertEqual(timeout.connect_timeout, 1.0)
|
||||
self.assertEqual(timeout.read_timeout, 1.5)
|
||||
self.assertEqual(timeout.total, 2.2)
|
||||
|
||||
def test_direct_timeout_respects_override(self):
|
||||
with patch.dict(
|
||||
"os.environ",
|
||||
{
|
||||
"DOMAINCHECK_REGISTER_DIRECT_CONNECT_TIMEOUT": "0.9",
|
||||
"DOMAINCHECK_REGISTER_DIRECT_READ_TIMEOUT": "1.4",
|
||||
"DOMAINCHECK_REGISTER_DIRECT_TOTAL_TIMEOUT": "1.7",
|
||||
},
|
||||
clear=False,
|
||||
):
|
||||
timeout = register._resolve_register_timeout(None)
|
||||
self.assertEqual(timeout.connect_timeout, 0.9)
|
||||
self.assertEqual(timeout.read_timeout, 1.4)
|
||||
self.assertEqual(timeout.total, 1.7)
|
||||
|
||||
def test_budget_clamps_proxy_timeout_into_remaining_window(self):
|
||||
with patch.dict("os.environ", {}, clear=False):
|
||||
timeout = register._resolve_register_timeout(
|
||||
{"http": "http://127.0.0.1:8080"},
|
||||
budget_seconds=0.8,
|
||||
)
|
||||
self.assertEqual(timeout.total, 0.8)
|
||||
self.assertLessEqual(timeout.connect_timeout, 0.35)
|
||||
self.assertLessEqual(timeout.read_timeout, 0.61)
|
||||
|
||||
def test_request_register_converts_urllib3_timeout_for_requests(self):
|
||||
session = MagicMock()
|
||||
response = MagicMock()
|
||||
session.get.return_value = response
|
||||
timeout = urllib3.Timeout(connect=1.1, read=1.7, total=2.4)
|
||||
with patch("domainCheck.detect.register._get_http_manager", return_value=session):
|
||||
result = register._request_register(
|
||||
"https://rdap.verisign.com/com/v1/domain/example",
|
||||
proxies={"http": "http://127.0.0.1:8080", "https": "http://127.0.0.1:8080"},
|
||||
timeout=timeout,
|
||||
)
|
||||
self.assertIs(result, response)
|
||||
session.get.assert_called_once_with(
|
||||
"https://rdap.verisign.com/com/v1/domain/example",
|
||||
timeout=(1.1, 1.7),
|
||||
proxies={"http": "http://127.0.0.1:8080", "https": "http://127.0.0.1:8080"},
|
||||
allow_redirects=True,
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user