#!/usr/bin/env python3
"""
简单验证 Client 默认超时时间
"""

import sys
from pathlib import Path
from unittest.mock import Mock, patch

# Add the parent directory to the path to import sandai
sys.path.insert(0, str(Path(__file__).parent.parent))

from sandai.operator_client import OperatorClient, create_client

def test_default_timeout():
    """测试默认超时时间"""
    with patch('sandai.operator_client.Celery'), \
         patch('sandai.operator.env.get_celery_config') as mock_get_config, \
         patch('sandai.operator.env.get_default_celery_config') as mock_default_config:
        
        # 模拟配置
        mock_config = Mock()
        mock_config.broker_url = "redis://localhost:6379/0"
        mock_config.result_backend = "redis://localhost:6379/0"
        
        mock_get_config.return_value = mock_config
        mock_default_config.return_value = mock_config
        
        # 创建客户端
        client = OperatorClient("test-operator", "v1")
        
        print(f"默认超时时间: {client.timeout} 秒")
        print(f"转换为小时: {client.timeout / 3600} 小时")
        
        expected = 8 * 60 * 60  # 8 小时
        if client.timeout == expected:
            print("✅ 默认超时时间正确设置为 8 小时")
            return True
        else:
            print(f"❌ 默认超时时间错误: 期望 {expected} 秒，实际 {client.timeout} 秒")
            return False

if __name__ == "__main__":
    success = test_default_timeout()
    sys.exit(0 if success else 1)