#!/usr/bin/env python3
"""测试容器内部连接"""

import requests
import time

# 后台启动服务
import subprocess
import os

print("🔧 后台启动API服务...")
proc = subprocess.Popen(['python', 'api_for_fixed_rpc.py'], 
                       stdout=open('api_test.log', 'w'), 
                       stderr=subprocess.STDOUT)

print(f"✅ 进程已启动，PID: {proc.pid}")

# 等待启动
time.sleep(5)

print("\n🔍 在容器内部测试连接 http://0.0.0.0:8088/ ...")
try:
    response = requests.get('http://0.0.0.0:8088/', timeout=5)
    print(f"✅ 请求成功，状态码: {response.status_code}")
    print(f"✅ 响应内容: {response.text}")
except Exception as e:
    print(f"❌ 请求失败: {e}")

# 查看日志
print("\n📝 服务日志:")
with open('api_test.log', 'r') as f:
    print(f.read())

# 不杀进程，让它继续运行
print(f"\n✅ 服务继续运行，PID: {proc.pid}")
