You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.9 KiB
62 lines
1.9 KiB
#!/usr/bin/env python3
|
|
"""
|
|
测试应用启动
|
|
"""
|
|
import asyncio
|
|
import sys
|
|
import os
|
|
|
|
# 添加项目根目录到Python路径
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
from app.core.app.factory import create_development_app
|
|
from app.utils.structured_log import get_structured_logger, LogLevel
|
|
|
|
logger = get_structured_logger(__name__, LogLevel.INFO)
|
|
|
|
async def test_app_startup():
|
|
"""测试应用启动"""
|
|
try:
|
|
logger.info("开始测试应用启动")
|
|
|
|
# 创建应用
|
|
app = create_development_app()
|
|
logger.info("应用创建成功")
|
|
|
|
# 模拟启动事件
|
|
logger.info("模拟启动事件")
|
|
startup_event = None
|
|
for route in app.routes:
|
|
if hasattr(route, 'methods') and 'GET' in route.methods and route.path == '/':
|
|
logger.info("找到根路径路由")
|
|
break
|
|
|
|
# 检查启动事件
|
|
if hasattr(app, 'router') and hasattr(app.router, 'startup'):
|
|
startup_events = app.router.startup
|
|
if hasattr(startup_events, '__len__'):
|
|
logger.info(f"启动事件数量: {len(startup_events)}")
|
|
for event in startup_events:
|
|
logger.info(f"启动事件: {event}")
|
|
else:
|
|
logger.info("启动事件存在但不是列表类型")
|
|
else:
|
|
logger.info("没有找到启动事件")
|
|
|
|
logger.info("应用启动测试完成")
|
|
return True
|
|
|
|
except Exception as e:
|
|
logger.error(f"应用启动测试失败: {e}")
|
|
import traceback
|
|
logger.error(f"异常堆栈: {traceback.format_exc()}")
|
|
return False
|
|
|
|
if __name__ == "__main__":
|
|
success = asyncio.run(test_app_startup())
|
|
if success:
|
|
print("✅ 应用启动测试成功")
|
|
sys.exit(0)
|
|
else:
|
|
print("❌ 应用启动测试失败")
|
|
sys.exit(1)
|
|
|