46 lines
1.1 KiB
Python
46 lines
1.1 KiB
Python
"""
|
|
等待服务启动并运行测试
|
|
"""
|
|
import time
|
|
import requests
|
|
import sys
|
|
|
|
def wait_for_server(url, max_wait=30):
|
|
"""等待服务启动"""
|
|
print("等待服务启动...")
|
|
|
|
for i in range(max_wait):
|
|
try:
|
|
response = requests.get(url, timeout=2)
|
|
if response.status_code == 200:
|
|
print(f"✓ 服务已启动!(等待了 {i+1} 秒)")
|
|
return True
|
|
except:
|
|
pass
|
|
|
|
time.sleep(1)
|
|
if (i + 1) % 5 == 0:
|
|
print(f" 已等待 {i+1} 秒...")
|
|
|
|
print("✗ 服务启动超时")
|
|
return False
|
|
|
|
if __name__ == '__main__':
|
|
base_url = "http://localhost:7500"
|
|
|
|
print("="*60)
|
|
print("等待服务启动并测试")
|
|
print("="*60)
|
|
|
|
if wait_for_server(base_url):
|
|
print("\n" + "="*60)
|
|
print("服务已就绪,可以运行测试脚本:")
|
|
print(" python test_complete.py")
|
|
print("="*60)
|
|
else:
|
|
print("\n请确保服务已启动:")
|
|
print(" python app.py")
|
|
sys.exit(1)
|
|
|
|
|