test_heartbeat_config.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/env python3
  2. """
  3. 测试心跳API是否正确返回配置信息
  4. """
  5. import requests
  6. import json
  7. import time
  8. def test_heartbeat_config():
  9. """测试心跳API返回配置信息"""
  10. print("🧪 测试心跳API配置更新功能")
  11. # 模拟登录获取session_id(这里需要先登录获取真实session_id)
  12. # 由于没有真实登录,这里只是展示API结构
  13. print("📝 心跳API响应结构示例:")
  14. example_response = {
  15. "code": 200,
  16. "msg": "成功",
  17. "data": {
  18. "expire_time": "2026-12-31T23:59:59",
  19. "server_time": "2026-01-06T17:23:25.000000",
  20. "session_status": "active",
  21. "next_heartbeat": 30,
  22. "session_expires_at": "2026-01-07T17:23:25.000000",
  23. "session_extend_enabled": True,
  24. "session_extend_threshold_hours": 4,
  25. "client_configs": {
  26. "api_timeout_seconds": 30,
  27. "client_heartbeat_interval_seconds": 30,
  28. "max_heartbeat_failures": 10,
  29. "max_network_failures": 15
  30. }
  31. },
  32. "timestamp": int(time.time())
  33. }
  34. print(json.dumps(example_response, indent=2, ensure_ascii=False))
  35. print("\n✅ 心跳API现在会返回以下配置信息:")
  36. print(" - api_timeout_seconds: API请求超时秒数")
  37. print(" - client_heartbeat_interval_seconds: 客户端心跳间隔秒数")
  38. print(" - max_heartbeat_failures: 最大心跳失败次数")
  39. print(" - max_network_failures: 网络异常最大失败次数")
  40. print("\n🔄 客户端会在每次心跳时自动更新这些配置,无需重启应用")
  41. if __name__ == "__main__":
  42. test_heartbeat_config()