Handle large proxy status responses
This commit is contained in:
@@ -23,6 +23,7 @@ def load_module():
|
||||
|
||||
class ApiFixtureHandler(BaseHTTPRequestHandler):
|
||||
requests: list[dict[str, Any]] = []
|
||||
large_status = False
|
||||
|
||||
def _json(self, status: int, payload: object) -> None:
|
||||
body = json.dumps(payload).encode("utf-8")
|
||||
@@ -36,7 +37,14 @@ class ApiFixtureHandler(BaseHTTPRequestHandler):
|
||||
parsed = urllib.parse.urlparse(self.path)
|
||||
type(self).requests.append({"method": "GET", "path": parsed.path, "query": urllib.parse.parse_qs(parsed.query)})
|
||||
if parsed.path == "/base/status.json":
|
||||
self._json(200, {"targets_up": 1, "targets_total": 1, "targets": [{"name": "pc", "ok": True}]})
|
||||
payload: dict[str, object] = {
|
||||
"targets_up": 1,
|
||||
"targets_total": 1,
|
||||
"targets": [{"name": "pc", "ok": True}],
|
||||
}
|
||||
if type(self).large_status:
|
||||
payload["padding"] = "x" * 1_100_000
|
||||
self._json(200, payload)
|
||||
return
|
||||
if parsed.path == "/base/admin/pc%20win/api/proxies":
|
||||
self._json(
|
||||
@@ -88,6 +96,7 @@ class ProxyMonitorTUITests(unittest.TestCase):
|
||||
|
||||
def setUp(self) -> None:
|
||||
ApiFixtureHandler.requests = []
|
||||
ApiFixtureHandler.large_status = False
|
||||
self.mod = load_module()
|
||||
self.base_url = f"http://127.0.0.1:{self.server.server_port}/base"
|
||||
self.client = self.mod.ProxyMonitorClient(self.base_url, 2)
|
||||
@@ -124,6 +133,13 @@ class ProxyMonitorTUITests(unittest.TestCase):
|
||||
],
|
||||
)
|
||||
|
||||
def test_status_response_larger_than_one_mebibyte_is_not_truncated(self) -> None:
|
||||
ApiFixtureHandler.large_status = True
|
||||
|
||||
status = self.client.fetch_status()
|
||||
|
||||
self.assertEqual(len(status["padding"]), 1_100_000)
|
||||
|
||||
def test_selector_groups_only_include_switchable_groups(self) -> None:
|
||||
groups = self.mod.normalize_selector_groups(
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user