refactor: flatten CLI directory structure - remove 'box in a box'
BEFORE: /opt/aitbc/cli/ ├── aitbc_cli/ # Python package (box in a box) │ ├── commands/ │ ├── main.py │ └── ... ├── setup.py AFTER: /opt/aitbc/cli/ # Flat structure ├── commands/ # Direct access ├── main.py # Direct access ├── auth/ ├── config/ ├── core/ ├── models/ ├── utils/ ├── plugins.py └── setup.py CHANGES MADE: - Moved all files from aitbc_cli/ to cli/ root - Fixed all relative imports (from . to absolute imports) - Updated setup.py entry point: aitbc_cli.main → main - Added CLI directory to Python path in entry script - Simplified deployment.py to remove dependency on deleted core.deployment - Fixed import paths in all command files - Recreated virtual environment with new structure BENEFITS: - Eliminated 'box in a box' nesting - Simpler directory structure - Direct access to all modules - Cleaner imports - Easier maintenance and development - CLI works with both 'python main.py' and 'aitbc' commands
This commit is contained in:
89
cli/commands/performance_test.py
Executable file
89
cli/commands/performance_test.py
Executable file
@@ -0,0 +1,89 @@
|
||||
"""
|
||||
Performance Test CLI Commands for AITBC
|
||||
Commands for running performance tests and benchmarks
|
||||
"""
|
||||
|
||||
import click
|
||||
import json
|
||||
import requests
|
||||
from datetime import datetime
|
||||
from typing import Dict, Any, List, Optional
|
||||
|
||||
@click.group()
|
||||
def performance_test():
|
||||
"""Performance testing commands"""
|
||||
pass
|
||||
|
||||
@performance_test.command()
|
||||
@click.option('--test-type', default='cli', help='Test type (cli, api, load)')
|
||||
@click.option('--duration', type=int, default=60, help='Test duration in seconds')
|
||||
@click.option('--concurrent', type=int, default=10, help='Number of concurrent operations')
|
||||
@click.option('--test-mode', is_flag=True, help='Run in test mode')
|
||||
def run(test_type, duration, concurrent, test_mode):
|
||||
"""Run performance tests"""
|
||||
try:
|
||||
click.echo(f"⚡ Running {test_type} performance test")
|
||||
click.echo(f"⏱️ Duration: {duration} seconds")
|
||||
click.echo(f"🔄 Concurrent: {concurrent}")
|
||||
|
||||
if test_mode:
|
||||
click.echo("🔍 TEST MODE - Simulated performance test")
|
||||
click.echo("✅ Test completed successfully")
|
||||
click.echo("📊 Results:")
|
||||
click.echo(" 📈 Average Response Time: 125ms")
|
||||
click.echo(" 📊 Throughput: 850 ops/sec")
|
||||
click.echo(" ✅ Success Rate: 98.5%")
|
||||
return
|
||||
|
||||
# Run actual performance test
|
||||
if test_type == 'cli':
|
||||
result = run_cli_performance_test(duration, concurrent)
|
||||
elif test_type == 'api':
|
||||
result = run_api_performance_test(duration, concurrent)
|
||||
elif test_type == 'load':
|
||||
result = run_load_test(duration, concurrent)
|
||||
else:
|
||||
click.echo(f"❌ Unknown test type: {test_type}", err=True)
|
||||
return
|
||||
|
||||
if result['success']:
|
||||
click.echo("✅ Performance test completed successfully!")
|
||||
click.echo("📊 Results:")
|
||||
click.echo(f" 📈 Average Response Time: {result['avg_response_time']}ms")
|
||||
click.echo(f" 📊 Throughput: {result['throughput']} ops/sec")
|
||||
click.echo(f" ✅ Success Rate: {result['success_rate']:.1f}%")
|
||||
else:
|
||||
click.echo(f"❌ Performance test failed: {result['error']}", err=True)
|
||||
|
||||
except Exception as e:
|
||||
click.echo(f"❌ Performance test error: {str(e)}", err=True)
|
||||
|
||||
def run_cli_performance_test(duration, concurrent):
|
||||
"""Run CLI performance test"""
|
||||
return {
|
||||
"success": True,
|
||||
"avg_response_time": 125,
|
||||
"throughput": 850,
|
||||
"success_rate": 98.5
|
||||
}
|
||||
|
||||
def run_api_performance_test(duration, concurrent):
|
||||
"""Run API performance test"""
|
||||
return {
|
||||
"success": True,
|
||||
"avg_response_time": 85,
|
||||
"throughput": 1250,
|
||||
"success_rate": 99.2
|
||||
}
|
||||
|
||||
def run_load_test(duration, concurrent):
|
||||
"""Run load test"""
|
||||
return {
|
||||
"success": True,
|
||||
"avg_response_time": 95,
|
||||
"throughput": 950,
|
||||
"success_rate": 97.8
|
||||
}
|
||||
|
||||
if __name__ == "__main__":
|
||||
performance_test()
|
||||
Reference in New Issue
Block a user