CreoOtkPluging/test_timeout.py
sladro 444307aea3 优化Shrinkwrap接口 - 解决复杂模型500错误问题
## 主要改进
- 新增动态超时机制:支持timeout_seconds参数(10-300秒)
- 增强异常处理:细分OTK异常类型,提供具体错误信息
- 保持向后兼容:新参数可选,不影响现有API

## 技术细节
- ShrinkwrapManager.h: 添加timeout_seconds字段
- ShellExportHandler.cpp: 实现超时参数解析和验证
- MFCCreoDll.cpp: HTTP层支持动态超时控制
- ShrinkwrapManager.cpp: 细分pfcXToolkitError等异常类型

## 解决问题
- 复杂模型处理超时导致的504错误
- 异常信息不明确难以定位问题
- 固定30秒超时限制了大模型处理能力

## 文档和测试
- SHRINKWRAP_OPTIMIZATION.md: 完整使用说明
- test_timeout.py/bat: 自动化和手动测试工具
- 更新CLAUDE.md项目文档

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-28 16:05:46 +08:00

109 lines
3.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""
简单的HTTP测试脚本测试shrinkwrap接口的timeout功能
"""
import json
import requests
import sys
import time
def test_shrinkwrap_timeout(timeout_seconds=60):
"""
测试shrinkwrap接口的超时功能
"""
url = "http://localhost:12345/api/creo/shrinkwrap/shell"
# 测试数据
test_data = {
"software_type": "creo",
"project_name": "Timeout Test",
"method": "outer_shell",
"quality": 5,
"chord_height": 0.1,
"fill_holes": False,
"ignore_small_surfaces": False,
"small_surface_percentage": 0.0,
"output_file_path": "test_shrinkwrap_timeout.prt",
"output_type": "solid_surface",
"ignore_quilts": True,
"ignore_skeleton": True,
"assign_mass_properties": False,
"preset": "balanced",
"timeout_seconds": timeout_seconds # 使用动态超时
}
headers = {
"Content-Type": "application/json"
}
print(f"测试shrinkwrap接口超时设置: {timeout_seconds}")
print(f"URL: {url}")
print(f"请求数据: {json.dumps(test_data, indent=2, ensure_ascii=False)}")
try:
start_time = time.time()
response = requests.post(url, json=test_data, headers=headers, timeout=timeout_seconds+10)
end_time = time.time()
print(f"请求耗时: {end_time - start_time:.2f}")
print(f"HTTP状态码: {response.status_code}")
print(f"响应内容: {response.text}")
if response.status_code == 200:
print("✓ 请求成功")
return True
elif response.status_code == 504:
print("✓ 超时处理正常")
return True
else:
print(f"✗ 请求失败: {response.status_code}")
return False
except requests.exceptions.Timeout:
print("✗ HTTP客户端超时")
return False
except requests.exceptions.ConnectionError:
print("✗ 连接失败请确保DLL服务正在运行")
return False
except Exception as e:
print(f"✗ 请求异常: {e}")
return False
def test_different_timeouts():
"""
测试不同的超时设置
"""
print("=== 测试不同超时设置 ===\n")
# 测试各种超时值
test_cases = [
{"timeout": 15, "desc": "短超时测试"},
{"timeout": 30, "desc": "默认超时测试"},
{"timeout": 120, "desc": "长超时测试"},
{"timeout": 5, "desc": "极短超时测试应被限制为10秒"},
{"timeout": 400, "desc": "超长超时测试应被限制为300秒"}
]
results = []
for case in test_cases:
print(f"--- {case['desc']} ---")
success = test_shrinkwrap_timeout(case['timeout'])
results.append({"case": case['desc'], "success": success})
print()
time.sleep(2) # 间隔等待
print("=== 测试结果汇总 ===")
for result in results:
status = "" if result['success'] else ""
print(f"{status} {result['case']}")
if __name__ == "__main__":
if len(sys.argv) > 1:
try:
timeout = int(sys.argv[1])
test_shrinkwrap_timeout(timeout)
except ValueError:
print("参数错误,请输入有效的超时秒数")
sys.exit(1)
else:
test_different_timeouts()