RobotHub-InferenceServer / test_integration.py
blanchon's picture
Update
63ed3a7
raw
history blame
4.86 kB
#!/usr/bin/env python3
"""
Test script for the integrated Inference Server setup
This script verifies that both the FastAPI API and Gradio UI work correctly.
"""
import asyncio
import sys
import time
from pathlib import Path
import httpx
# Add src to path
src_path = Path(__file__).parent / "src"
sys.path.insert(0, str(src_path))
async def test_api_endpoints():
"""Test that the FastAPI endpoints work correctly."""
base_url = "http://localhost:7860"
async with httpx.AsyncClient(timeout=10.0) as client:
try:
# Test main health endpoint
print("πŸ” Testing main health endpoint...")
response = await client.get(f"{base_url}/api/health")
assert response.status_code == 200
data = response.json()
print(f"βœ… Health check passed: {data}")
# Test API docs availability
print("πŸ“– Testing API docs availability...")
response = await client.get(f"{base_url}/api/docs")
assert response.status_code == 200
print("βœ… API docs available")
# Test OpenAPI schema
print("πŸ“‹ Testing OpenAPI schema...")
response = await client.get(f"{base_url}/api/openapi.json")
assert response.status_code == 200
schema = response.json()
print(f"βœ… OpenAPI schema available: {schema['info']['title']}")
# Test sessions endpoint
print("πŸ“ Testing sessions endpoint...")
response = await client.get(f"{base_url}/api/sessions")
assert response.status_code == 200
sessions = response.json()
print(f"βœ… Sessions endpoint works: {len(sessions)} sessions")
# Test Gradio UI availability
print("🎨 Testing Gradio UI availability...")
response = await client.get(f"{base_url}/")
assert response.status_code == 200
print("βœ… Gradio UI available")
print("\nπŸŽ‰ All tests passed! The integrated setup is working correctly.")
return True
except Exception as e:
print(f"❌ Test failed: {e}")
return False
async def test_session_creation():
"""Test creating a session through the API."""
base_url = "http://localhost:7860"
async with httpx.AsyncClient(timeout=30.0) as client:
try:
# Create a test session
print("πŸ”§ Testing session creation...")
session_data = {
"session_id": "test-session",
"policy_path": "./checkpoints/act_so101_beyond",
"camera_names": ["front"],
"arena_server_url": "http://localhost:8000",
}
response = await client.post(f"{base_url}/api/sessions", json=session_data)
if response.status_code == 200:
print("βœ… Session creation successful")
return True
print(
f"⚠️ Session creation failed (expected if no model exists): {response.status_code}"
)
return True # This is expected if no model exists
except Exception as e:
print(f"⚠️ Session creation test failed (expected if no model exists): {e}")
return True # This is expected if no model exists
def print_integration_info():
"""Print information about the integrated setup."""
print("=" * 60)
print("πŸ€– Integrated Inference Server Test Results")
print("=" * 60)
print()
print("πŸ“ Access Points:")
print(" 🎨 Gradio UI: http://localhost:7860/")
print(" πŸ“– API Docs: http://localhost:7860/api/docs")
print(" πŸ”„ Health Check: http://localhost:7860/api/health")
print(" πŸ“‹ OpenAPI Schema: http://localhost:7860/api/openapi.json")
print(" πŸ“ Sessions API: http://localhost:7860/api/sessions")
print()
print("πŸ”§ Features Available:")
print(" βœ… Direct session management through UI")
print(" βœ… Full REST API for programmatic access")
print(" βœ… Interactive API documentation")
print(" βœ… Single port deployment")
print(" βœ… CORS enabled for frontend integration")
print()
if __name__ == "__main__":
print("πŸ§ͺ Testing Integrated Inference Server Setup")
print("Make sure the server is running with: python launch_simple.py")
print()
# Wait a moment for server to be ready
time.sleep(2)
# Run tests
try:
success = asyncio.run(test_api_endpoints())
if success:
asyncio.run(test_session_creation())
print_integration_info()
except KeyboardInterrupt:
print("\nπŸ›‘ Tests interrupted by user")
except Exception as e:
print(f"❌ Test runner error: {e}")
sys.exit(1)