From 5071434cd3b6c652d95ac8b2026dd173a7fbbace Mon Sep 17 00:00:00 2001 From: Alexander_Kabui Date: Sun, 4 Oct 2026 13:07:44 +0300 Subject: * src/routes/search.rs (search): share one reqwest client with a total timeout for gn3 calls reqwest::get built a fresh client per query (no keepalive) and set no timeout, while gn3 sets none of its own -- a stalled upstream would hang the handler past any front-proxy timeout. One shared client in a OnceLock now, mirroring the shared-DB-pool pattern. * src/config.rs (Config): add GN3_TIMEOUT_SECS (default 30); normalize GN3_URL to end with a slash. * tests/search.rs test/python/test_search.py (search): one scenario mapping a gn3 5xx to the 502 backend_error shape. --- test/python/test_search.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'test/python') diff --git a/test/python/test_search.py b/test/python/test_search.py index d8c5cc5..027501f 100644 --- a/test/python/test_search.py +++ b/test/python/test_search.py @@ -23,9 +23,12 @@ class Gn3StubHandler(http.server.BaseHTTPRequestHandler): def do_GET(self): query = urllib.parse.parse_qs(urllib.parse.urlparse(self.path).query) - if "&&" in query.get("query", [""])[0]: - # Mirrors production gn3's shape (live-checked Oct 4): - # diagnostic under "error", Python repr under "error_type". + if "boom" in query.get("query", [""])[0]: + body = b'{"error": "gn3 exploded"}' + self.send_response(http.client.INTERNAL_SERVER_ERROR) + elif "&&" in query.get("query", [""])[0]: + # Mirrors production gn3's shape: diagnostic under + # "error", Python repr under "error_type". body = json.dumps( { "error": "Syntax: AND ", @@ -99,6 +102,11 @@ class SearchTest(ServerTestCase): status, _ = self.get("/search?q=alcohol&limit=9999") self.assertEqual(status, http.client.OK) + def test_search_maps_gn3_failures_to_502(self): + status, body = self.get("/search?q=boom") + self.assertEqual(status, http.client.BAD_GATEWAY) + self.assertEqual(body["code"], "backend_error") + if __name__ == "__main__": unittest.main() -- cgit 1.4.1