about summary refs log tree commit diff
path: root/test/python
diff options
context:
space:
mode:
authorAlexander_Kabui <alexanderkabua@gmail.com>2026-10-04 13:07:44 +0300
committerAlexander_Kabui <alexanderkabua@gmail.com>2026-10-05 21:54:17 +0300
commit5071434cd3b6c652d95ac8b2026dd173a7fbbace (patch)
tree03e2b33aa0ebe468a89023eaf060073c8e9382b2 /test/python
parent98b71eb8c080c21ca458961805019170c794fdc7 (diff)
downloadgenenetwork4-5071434cd3b6c652d95ac8b2026dd173a7fbbace.tar.gz
* 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.
Diffstat (limited to 'test/python')
-rw-r--r--test/python/test_search.py14
1 files changed, 11 insertions, 3 deletions
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: <expression> AND <expression>",
@@ -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()