初版:小白超人(从线上实例导出)

This commit is contained in:
deploy
2026-10-29 15:20:39 +08:00
commit b77a309873
100 changed files with 32168 additions and 0 deletions
+53
View File
@@ -0,0 +1,53 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""真实启动冒烟测试: 执行 app.py 的完整启动序列并验证 HTTP 服务可响应。
唯一差异: start_rental_timer 被置空, 避免测试期间触发真实提醒邮件/自动还车。"""
import sys
import threading
import time
import urllib.request
import timer
timer.start_rental_timer = lambda *a, **k: None # 防止测试期间发出真实邮件
import app as app_module
app_module.init_db()
app_module.backup_database()
print("[smoke] init_db + backup 完成")
app_module.restore_active_timers()
app_module.start_all_order_checkers()
app_module.start_snapshot_scheduler()
PORT = 9987
t = threading.Thread(
target=lambda: app_module.app.run(host="127.0.0.1", port=PORT, debug=False),
daemon=True,
)
t.start()
# 等待服务就绪
ok = False
for _ in range(30):
time.sleep(0.3)
try:
with urllib.request.urlopen(f"http://127.0.0.1:{PORT}/", timeout=3) as r:
body = r.read(200)
print(f"[smoke] GET / -> {r.status}, body[:60]={body[:60]!r}")
ok = r.status == 200
break
except Exception:
continue
# 再打两个关键接口
for path in ("/api/config", "/api/history/stats"):
try:
with urllib.request.urlopen(f"http://127.0.0.1:{PORT}{path}", timeout=5) as r:
print(f"[smoke] GET {path} -> {r.status}")
except Exception as e:
print(f"[smoke] GET {path} -> 异常 {e}")
ok = False
import os
os._exit(0 if ok else 1)