Add an HTTP-level regression path for the local ACR service
Constraint: A service intended for industrialization needs a real process-level smoke test, not only direct function imports Rejected: Rely on unit-style handler calls alone | Misses uvicorn startup and actual HTTP surface regressions Confidence: high Scope-risk: narrow Directive: Keep service_smoke.py lightweight and dependency-free so it remains the fastest operational gate before broader API expansion Tested: /usr/local/miniconda3/bin/python -m py_compile acr-engine/scripts/service_smoke.py; /usr/local/miniconda3/bin/python acr-engine/scripts/service_smoke.py Not-tested: /recognize and /index/build over HTTP remain pending dedicated API smoke inputs
Showing
4 changed files
with
139 additions
and
4 deletions
| ... | @@ -11,10 +11,8 @@ | ... | @@ -11,10 +11,8 @@ |
| 11 | 11 | ||
| 12 | ```bash | 12 | ```bash |
| 13 | cd acr-engine | 13 | cd acr-engine |
| 14 | python -m venv .venv | 14 | /usr/local/miniconda3/bin/python -m pip install -r requirements.txt |
| 15 | source .venv/bin/activate | 15 | /usr/local/miniconda3/bin/python run_demo.py full-demo --device cpu |
| 16 | pip install -r requirements.txt | ||
| 17 | python run_demo.py full-demo | ||
| 18 | ``` | 16 | ``` |
| 19 | 17 | ||
| 20 | ## 常用命令 | 18 | ## 常用命令 |
| ... | @@ -53,6 +51,30 @@ python run_demo.py recognize \ | ... | @@ -53,6 +51,30 @@ python run_demo.py recognize \ |
| 53 | python run_demo.py full-demo --device cpu | 51 | python run_demo.py full-demo --device cpu |
| 54 | ``` | 52 | ``` |
| 55 | 53 | ||
| 54 | |||
| 55 | ## 服务启动与 smoke | ||
| 56 | |||
| 57 | ### 启动服务 | ||
| 58 | |||
| 59 | ```bash | ||
| 60 | cd acr-engine | ||
| 61 | /usr/local/miniconda3/bin/python -m uvicorn src.service.app:app --host 127.0.0.1 --port 8000 | ||
| 62 | ``` | ||
| 63 | |||
| 64 | ### 运行服务 smoke | ||
| 65 | |||
| 66 | ```bash | ||
| 67 | cd acr-engine | ||
| 68 | /usr/local/miniconda3/bin/python scripts/service_smoke.py | ||
| 69 | ``` | ||
| 70 | |||
| 71 | ### 常看接口 | ||
| 72 | |||
| 73 | - `GET /health` | ||
| 74 | - `GET /ready` | ||
| 75 | - `GET /config` | ||
| 76 | - `GET /cache` | ||
| 77 | |||
| 56 | ## 目录 | 78 | ## 目录 |
| 57 | 79 | ||
| 58 | - `train.py`:训练入口 | 80 | - `train.py`:训练入口 | ... | ... |
acr-engine/scripts/service_smoke.py
0 → 100755
| 1 | #!/usr/bin/env python3 | ||
| 2 | """Minimal local smoke test for the FastAPI ACR service.""" | ||
| 3 | |||
| 4 | from __future__ import annotations | ||
| 5 | |||
| 6 | import json | ||
| 7 | import subprocess | ||
| 8 | import time | ||
| 9 | from urllib.request import urlopen | ||
| 10 | from urllib.error import URLError, HTTPError | ||
| 11 | |||
| 12 | BASE = "http://127.0.0.1:8000" | ||
| 13 | |||
| 14 | |||
| 15 | def fetch_json(path: str): | ||
| 16 | with urlopen(BASE + path, timeout=10) as resp: | ||
| 17 | return json.loads(resp.read().decode("utf-8")) | ||
| 18 | |||
| 19 | |||
| 20 | def main(): | ||
| 21 | cmd = [ | ||
| 22 | "/usr/local/miniconda3/bin/python", | ||
| 23 | "-m", | ||
| 24 | "uvicorn", | ||
| 25 | "src.service.app:app", | ||
| 26 | "--host", | ||
| 27 | "127.0.0.1", | ||
| 28 | "--port", | ||
| 29 | "8000", | ||
| 30 | ] | ||
| 31 | proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) | ||
| 32 | try: | ||
| 33 | last_error = None | ||
| 34 | for _ in range(20): | ||
| 35 | time.sleep(0.5) | ||
| 36 | try: | ||
| 37 | health = fetch_json("/health") | ||
| 38 | ready = fetch_json("/ready") | ||
| 39 | config = fetch_json("/config") | ||
| 40 | cache = fetch_json("/cache") | ||
| 41 | print(json.dumps({ | ||
| 42 | "status": "ok", | ||
| 43 | "health": health, | ||
| 44 | "ready": ready, | ||
| 45 | "config": config, | ||
| 46 | "cache": cache, | ||
| 47 | }, indent=2, ensure_ascii=False)) | ||
| 48 | return | ||
| 49 | except (URLError, HTTPError, ConnectionError) as exc: | ||
| 50 | last_error = str(exc) | ||
| 51 | raise SystemExit(json.dumps({ | ||
| 52 | "status": "failed", | ||
| 53 | "reason": "service_not_ready_in_time", | ||
| 54 | "last_error": last_error, | ||
| 55 | }, indent=2, ensure_ascii=False)) | ||
| 56 | finally: | ||
| 57 | proc.terminate() | ||
| 58 | try: | ||
| 59 | proc.wait(timeout=5) | ||
| 60 | except subprocess.TimeoutExpired: | ||
| 61 | proc.kill() | ||
| 62 | proc.wait(timeout=5) | ||
| 63 | |||
| 64 | |||
| 65 | if __name__ == "__main__": | ||
| 66 | main() |
| ... | @@ -228,6 +228,31 @@ | ... | @@ -228,6 +228,31 @@ |
| 228 | 228 | ||
| 229 | 229 | ||
| 230 | 230 | ||
| 231 | |||
| 232 | ### Stage: 服务 HTTP smoke | ||
| 233 | |||
| 234 | 完成项: | ||
| 235 | - 新增 [acr-engine/scripts/service_smoke.py](../acr-engine/scripts/service_smoke.py) | ||
| 236 | - 用 `uvicorn` 真正拉起 FastAPI 服务,而不是只做函数级调用 | ||
| 237 | - 更新 [acr-engine/README.md](../acr-engine/README.md) 与 [docs/service-api.md](./service-api.md) 的服务运行说明 | ||
| 238 | |||
| 239 | 验证结果: | ||
| 240 | - `/usr/local/miniconda3/bin/python -m py_compile scripts/service_smoke.py` 成功 | ||
| 241 | - `/usr/local/miniconda3/bin/python scripts/service_smoke.py` 成功 | ||
| 242 | - 当前 smoke 已验证: | ||
| 243 | - `/health` | ||
| 244 | - `/ready` | ||
| 245 | - `/config` | ||
| 246 | - `/cache` | ||
| 247 | - 当前结果: | ||
| 248 | - `health.ready=true` | ||
| 249 | - `ready.ready=true` | ||
| 250 | - `engine_cache_size=0`(未执行 recognize 前) | ||
| 251 | |||
| 252 | 结论: | ||
| 253 | - 服务现在已经具备最小 HTTP 级 smoke 验证 | ||
| 254 | - 后续继续做鉴权、异步任务、监控时,有了更真实的回归入口 | ||
| 255 | |||
| 231 | ### Stage: 服务就绪探针与缓存可见性 | 256 | ### Stage: 服务就绪探针与缓存可见性 |
| 232 | 257 | ||
| 233 | 完成项: | 258 | 完成项: | ... | ... |
| ... | @@ -117,5 +117,27 @@ sequenceDiagram | ... | @@ -117,5 +117,27 @@ sequenceDiagram |
| 117 | 返回当前进程内 engine cache 统计。 | 117 | 返回当前进程内 engine cache 统计。 |
| 118 | 118 | ||
| 119 | 119 | ||
| 120 | |||
| 121 | ## 6. 本地运行与 smoke | ||
| 122 | |||
| 123 | ```bash | ||
| 124 | cd acr-engine | ||
| 125 | /usr/local/miniconda3/bin/python -m uvicorn src.service.app:app --host 127.0.0.1 --port 8000 | ||
| 126 | ``` | ||
| 127 | |||
| 128 | 另一个终端可直接执行: | ||
| 129 | |||
| 130 | ```bash | ||
| 131 | cd acr-engine | ||
| 132 | /usr/local/miniconda3/bin/python scripts/service_smoke.py | ||
| 133 | ``` | ||
| 134 | |||
| 135 | 该 smoke 当前会校验: | ||
| 136 | |||
| 137 | - `/health` | ||
| 138 | - `/ready` | ||
| 139 | - `/config` | ||
| 140 | - `/cache` | ||
| 141 | |||
| 120 | ## Sources | 142 | ## Sources |
| 121 | - See [references-and-sources.md](./references-and-sources.md) for the current source map. | 143 | - See [references-and-sources.md](./references-and-sources.md) for the current source map. | ... | ... |
-
Please register or sign in to post a comment