Compare commits
4 Commits
f79e514fc2
...
b7a69fa99a
| Author | SHA1 | Date | |
|---|---|---|---|
| b7a69fa99a | |||
| 101e3c4fb3 | |||
| 27510ebf2c | |||
| a8b631edc0 |
@@ -172,49 +172,47 @@ jobs:
|
||||
echo "🧪 Testing Coordinator API endpoints..."
|
||||
|
||||
# Create coordinator API test
|
||||
cat > test_coordinator_api.py << 'EOF'
|
||||
import requests
|
||||
import json
|
||||
|
||||
def test_coordinator_health():
|
||||
try:
|
||||
response = requests.get('http://localhost:8000/', timeout=5)
|
||||
print(f"✅ Coordinator health check: {response.status_code}")
|
||||
return response.status_code == 200
|
||||
except Exception as e:
|
||||
print(f"❌ Coordinator health error: {e}")
|
||||
return False
|
||||
|
||||
def test_coordinator_endpoints():
|
||||
endpoints = [
|
||||
'http://localhost:8000/',
|
||||
'http://localhost:8000/health',
|
||||
'http://localhost:8000/info'
|
||||
]
|
||||
|
||||
results = []
|
||||
for endpoint in endpoints:
|
||||
try:
|
||||
response = requests.get(endpoint, timeout=5)
|
||||
print(f"✅ {endpoint}: {response.status_code}")
|
||||
results.append(response.status_code == 200)
|
||||
except Exception as e:
|
||||
print(f"❌ {endpoint}: {e}")
|
||||
results.append(False)
|
||||
|
||||
return all(results)
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("🧪 Testing Coordinator API...")
|
||||
|
||||
health_ok = test_coordinator_health()
|
||||
endpoints_ok = test_coordinator_endpoints()
|
||||
|
||||
if health_ok and endpoints_ok:
|
||||
print("✅ Coordinator API tests passed")
|
||||
else:
|
||||
print("❌ Coordinator API tests failed")
|
||||
EOF
|
||||
echo 'import requests' > test_coordinator_api.py
|
||||
echo 'import json' >> test_coordinator_api.py
|
||||
echo '' >> test_coordinator_api.py
|
||||
echo 'def test_coordinator_health():' >> test_coordinator_api.py
|
||||
echo ' try:' >> test_coordinator_api.py
|
||||
echo ' response = requests.get('"'"'http://localhost:8000/'"'"', timeout=5)' >> test_coordinator_api.py
|
||||
echo ' print(f"✅ Coordinator health check: {response.status_code}")' >> test_coordinator_api.py
|
||||
echo ' return response.status_code == 200' >> test_coordinator_api.py
|
||||
echo ' except Exception as e:' >> test_coordinator_api.py
|
||||
echo ' print(f"❌ Coordinator health error: {e}")' >> test_coordinator_api.py
|
||||
echo ' return False' >> test_coordinator_api.py
|
||||
echo '' >> test_coordinator_api.py
|
||||
echo 'def test_coordinator_endpoints():' >> test_coordinator_api.py
|
||||
echo ' endpoints = [' >> test_coordinator_api.py
|
||||
echo ' '"'"'http://localhost:8000/'"'"',' >> test_coordinator_api.py
|
||||
echo ' '"'"'http://localhost:8000/health'"'"',' >> test_coordinator_api.py
|
||||
echo ' '"'"'http://localhost:8000/info'"'"'' >> test_coordinator_api.py
|
||||
echo ' ]' >> test_coordinator_api.py
|
||||
echo ' ' >> test_coordinator_api.py
|
||||
echo ' results = []' >> test_coordinator_api.py
|
||||
echo ' for endpoint in endpoints:' >> test_coordinator_api.py
|
||||
echo ' try:' >> test_coordinator_api.py
|
||||
echo ' response = requests.get(endpoint, timeout=5)' >> test_coordinator_api.py
|
||||
echo ' print(f"✅ {endpoint}: {response.status_code}")' >> test_coordinator_api.py
|
||||
echo ' results.append(response.status_code == 200)' >> test_coordinator_api.py
|
||||
echo ' except Exception as e:' >> test_coordinator_api.py
|
||||
echo ' print(f"❌ {endpoint}: {e}")' >> test_coordinator_api.py
|
||||
echo ' results.append(False)' >> test_coordinator_api.py
|
||||
echo ' ' >> test_coordinator_api.py
|
||||
echo ' return all(results)' >> test_coordinator_api.py
|
||||
echo '' >> test_coordinator_api.py
|
||||
echo 'if __name__ == "__main__":' >> test_coordinator_api.py
|
||||
echo ' print("🧪 Testing Coordinator API...")' >> test_coordinator_api.py
|
||||
echo ' ' >> test_coordinator_api.py
|
||||
echo ' health_ok = test_coordinator_health()' >> test_coordinator_api.py
|
||||
echo ' endpoints_ok = test_coordinator_endpoints()' >> test_coordinator_api.py
|
||||
echo ' ' >> test_coordinator_api.py
|
||||
echo ' if health_ok and endpoints_ok:' >> test_coordinator_api.py
|
||||
echo ' print("✅ Coordinator API tests passed")' >> test_coordinator_api.py
|
||||
echo ' else:' >> test_coordinator_api.py
|
||||
echo ' print("❌ Coordinator API tests failed")' >> test_coordinator_api.py
|
||||
|
||||
python test_coordinator_api.py
|
||||
|
||||
@@ -229,49 +227,47 @@ EOF
|
||||
echo "🧪 Testing Exchange API endpoints..."
|
||||
|
||||
# Create exchange API test
|
||||
cat > test_exchange_api.py << 'EOF'
|
||||
import requests
|
||||
import json
|
||||
|
||||
def test_exchange_health():
|
||||
try:
|
||||
response = requests.get('http://localhost:8001/', timeout=5)
|
||||
print(f"✅ Exchange health check: {response.status_code}")
|
||||
return response.status_code == 200
|
||||
except Exception as e:
|
||||
print(f"❌ Exchange health error: {e}")
|
||||
return False
|
||||
|
||||
def test_exchange_endpoints():
|
||||
endpoints = [
|
||||
'http://localhost:8001/',
|
||||
'http://localhost:8001/health',
|
||||
'http://localhost:8001/markets'
|
||||
]
|
||||
|
||||
results = []
|
||||
for endpoint in endpoints:
|
||||
try:
|
||||
response = requests.get(endpoint, timeout=5)
|
||||
print(f"✅ {endpoint}: {response.status_code}")
|
||||
results.append(response.status_code == 200)
|
||||
except Exception as e:
|
||||
print(f"❌ {endpoint}: {e}")
|
||||
results.append(False)
|
||||
|
||||
return all(results)
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("🧪 Testing Exchange API...")
|
||||
|
||||
health_ok = test_exchange_health()
|
||||
endpoints_ok = test_exchange_endpoints()
|
||||
|
||||
if health_ok and endpoints_ok:
|
||||
print("✅ Exchange API tests passed")
|
||||
else:
|
||||
print("❌ Exchange API tests failed")
|
||||
EOF
|
||||
echo 'import requests' > test_exchange_api.py
|
||||
echo 'import json' >> test_exchange_api.py
|
||||
echo '' >> test_exchange_api.py
|
||||
echo 'def test_exchange_health():' >> test_exchange_api.py
|
||||
echo ' try:' >> test_exchange_api.py
|
||||
echo ' response = requests.get('"'"'http://localhost:8001/'"'"', timeout=5)' >> test_exchange_api.py
|
||||
echo ' print(f"✅ Exchange health check: {response.status_code}")' >> test_exchange_api.py
|
||||
echo ' return response.status_code == 200' >> test_exchange_api.py
|
||||
echo ' except Exception as e:' >> test_exchange_api.py
|
||||
echo ' print(f"❌ Exchange health error: {e}")' >> test_exchange_api.py
|
||||
echo ' return False' >> test_exchange_api.py
|
||||
echo '' >> test_exchange_api.py
|
||||
echo 'def test_exchange_endpoints():' >> test_exchange_api.py
|
||||
echo ' endpoints = [' >> test_exchange_api.py
|
||||
echo ' '"'"'http://localhost:8001/'"'"',' >> test_exchange_api.py
|
||||
echo ' '"'"'http://localhost:8001/health'"'"',' >> test_exchange_api.py
|
||||
echo ' '"'"'http://localhost:8001/info'"'"'' >> test_exchange_api.py
|
||||
echo ' ]' >> test_exchange_api.py
|
||||
echo ' ' >> test_exchange_api.py
|
||||
echo ' results = []' >> test_exchange_api.py
|
||||
echo ' for endpoint in endpoints:' >> test_exchange_api.py
|
||||
echo ' try:' >> test_exchange_api.py
|
||||
echo ' response = requests.get(endpoint, timeout=5)' >> test_exchange_api.py
|
||||
echo ' print(f"✅ {endpoint}: {response.status_code}")' >> test_exchange_api.py
|
||||
echo ' results.append(response.status_code == 200)' >> test_exchange_api.py
|
||||
echo ' except Exception as e:' >> test_exchange_api.py
|
||||
echo ' print(f"❌ {endpoint}: {e}")' >> test_exchange_api.py
|
||||
echo ' results.append(False)' >> test_exchange_api.py
|
||||
echo ' ' >> test_exchange_api.py
|
||||
echo ' return all(results)' >> test_exchange_api.py
|
||||
echo '' >> test_exchange_api.py
|
||||
echo 'if __name__ == "__main__":' >> test_exchange_api.py
|
||||
echo ' print("🧪 Testing Exchange API...")' >> test_exchange_api.py
|
||||
echo ' ' >> test_exchange_api.py
|
||||
echo ' health_ok = test_exchange_health()' >> test_exchange_api.py
|
||||
echo ' endpoints_ok = test_exchange_endpoints()' >> test_exchange_api.py
|
||||
echo ' ' >> test_exchange_api.py
|
||||
echo ' if health_ok and endpoints_ok:' >> test_exchange_api.py
|
||||
echo ' print("✅ Exchange API tests passed")' >> test_exchange_api.py
|
||||
echo ' else:' >> test_exchange_api.py
|
||||
echo ' print("❌ Exchange API tests failed")' >> test_exchange_api.py
|
||||
|
||||
python test_exchange_api.py
|
||||
|
||||
@@ -286,49 +282,47 @@ EOF
|
||||
echo "🧪 Testing Wallet API endpoints..."
|
||||
|
||||
# Create wallet API test
|
||||
cat > test_wallet_api.py << 'EOF'
|
||||
import requests
|
||||
import json
|
||||
|
||||
def test_wallet_health():
|
||||
try:
|
||||
response = requests.get('http://localhost:8002/', timeout=5)
|
||||
print(f"✅ Wallet health check: {response.status_code}")
|
||||
return response.status_code == 200
|
||||
except Exception as e:
|
||||
print(f"❌ Wallet health error: {e}")
|
||||
return False
|
||||
|
||||
def test_wallet_endpoints():
|
||||
endpoints = [
|
||||
'http://localhost:8002/',
|
||||
'http://localhost:8002/health',
|
||||
'http://localhost:8002/wallets'
|
||||
]
|
||||
|
||||
results = []
|
||||
for endpoint in endpoints:
|
||||
try:
|
||||
response = requests.get(endpoint, timeout=5)
|
||||
print(f"✅ {endpoint}: {response.status_code}")
|
||||
results.append(response.status_code == 200)
|
||||
except Exception as e:
|
||||
print(f"❌ {endpoint}: {e}")
|
||||
results.append(False)
|
||||
|
||||
return all(results)
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("🧪 Testing Wallet API...")
|
||||
|
||||
health_ok = test_wallet_health()
|
||||
endpoints_ok = test_wallet_endpoints()
|
||||
|
||||
if health_ok and endpoints_ok:
|
||||
print("✅ Wallet API tests passed")
|
||||
else:
|
||||
print("❌ Wallet API tests failed")
|
||||
EOF
|
||||
echo 'import requests' > test_wallet_api.py
|
||||
echo 'import json' >> test_wallet_api.py
|
||||
echo '' >> test_wallet_api.py
|
||||
echo 'def test_wallet_health():' >> test_wallet_api.py
|
||||
echo ' try:' >> test_wallet_api.py
|
||||
echo ' response = requests.get('"'"'http://localhost:8002/'"'"', timeout=5)' >> test_wallet_api.py
|
||||
echo ' print(f"✅ Wallet health check: {response.status_code}")' >> test_wallet_api.py
|
||||
echo ' return response.status_code == 200' >> test_wallet_api.py
|
||||
echo ' except Exception as e:' >> test_wallet_api.py
|
||||
echo ' print(f"❌ Wallet health error: {e}")' >> test_wallet_api.py
|
||||
echo ' return False' >> test_wallet_api.py
|
||||
echo '' >> test_wallet_api.py
|
||||
echo 'def test_wallet_endpoints():' >> test_wallet_api.py
|
||||
echo ' endpoints = [' >> test_wallet_api.py
|
||||
echo ' '"'"'http://localhost:8002/'"'"',' >> test_wallet_api.py
|
||||
echo ' '"'"'http://localhost:8002/health'"'"',' >> test_wallet_api.py
|
||||
echo ' '"'"'http://localhost:8002/wallets'"'"'' >> test_wallet_api.py
|
||||
echo ' ]' >> test_wallet_api.py
|
||||
echo ' ' >> test_wallet_api.py
|
||||
echo ' results = []' >> test_wallet_api.py
|
||||
echo ' for endpoint in endpoints:' >> test_wallet_api.py
|
||||
echo ' try:' >> test_wallet_api.py
|
||||
echo ' response = requests.get(endpoint, timeout=5)' >> test_wallet_api.py
|
||||
echo ' print(f"✅ {endpoint}: {response.status_code}")' >> test_wallet_api.py
|
||||
echo ' results.append(response.status_code == 200)' >> test_wallet_api.py
|
||||
echo ' except Exception as e:' >> test_wallet_api.py
|
||||
echo ' print(f"❌ {endpoint}: {e}")' >> test_wallet_api.py
|
||||
echo ' results.append(False)' >> test_wallet_api.py
|
||||
echo ' ' >> test_wallet_api.py
|
||||
echo ' return all(results)' >> test_wallet_api.py
|
||||
echo '' >> test_wallet_api.py
|
||||
echo 'if __name__ == "__main__":' >> test_wallet_api.py
|
||||
echo ' print("🧪 Testing Wallet API...")' >> test_wallet_api.py
|
||||
echo ' ' >> test_wallet_api.py
|
||||
echo ' health_ok = test_wallet_health()' >> test_wallet_api.py
|
||||
echo ' endpoints_ok = test_wallet_endpoints()' >> test_wallet_api.py
|
||||
echo ' ' >> test_wallet_api.py
|
||||
echo ' if health_ok and endpoints_ok:' >> test_wallet_api.py
|
||||
echo ' print("✅ Wallet API tests passed")' >> test_wallet_api.py
|
||||
echo ' else:' >> test_wallet_api.py
|
||||
echo ' print("❌ Wallet API tests failed")' >> test_wallet_api.py
|
||||
|
||||
python test_wallet_api.py
|
||||
|
||||
@@ -343,71 +337,69 @@ EOF
|
||||
echo "🧪 Testing Blockchain RPC endpoints..."
|
||||
|
||||
# Create blockchain RPC test
|
||||
cat > test_blockchain_rpc.py << 'EOF'
|
||||
import requests
|
||||
import json
|
||||
|
||||
def test_rpc_connection():
|
||||
try:
|
||||
payload = {
|
||||
"jsonrpc": "2.0",
|
||||
"method": "eth_blockNumber",
|
||||
"params": [],
|
||||
"id": 1
|
||||
}
|
||||
response = requests.post('http://localhost:8545', json=payload, timeout=5)
|
||||
if response.status_code == 200:
|
||||
result = response.json()
|
||||
print(f"✅ RPC connection: {result.get('result', 'Unknown block number')}")
|
||||
return True
|
||||
else:
|
||||
print(f"❌ RPC connection failed: {response.status_code}")
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"❌ RPC connection error: {e}")
|
||||
return False
|
||||
|
||||
def test_rpc_methods():
|
||||
methods = [
|
||||
{"method": "eth_chainId", "params": []},
|
||||
{"method": "eth_getBlockByNumber", "params": ["latest", False]},
|
||||
{"method": "net_version", "params": []}
|
||||
]
|
||||
|
||||
results = []
|
||||
for method in methods:
|
||||
try:
|
||||
payload = {
|
||||
"jsonrpc": "2.0",
|
||||
"method": method["method"],
|
||||
"params": method["params"],
|
||||
"id": 1
|
||||
}
|
||||
response = requests.post('http://localhost:8545', json=payload, timeout=5)
|
||||
if response.status_code == 200:
|
||||
result = response.json()
|
||||
print(f"✅ {method['method']}: {result.get('result', 'Success')}")
|
||||
results.append(True)
|
||||
else:
|
||||
print(f"❌ {method['method']}: {response.status_code}")
|
||||
results.append(False)
|
||||
except Exception as e:
|
||||
print(f"❌ {method['method']}: {e}")
|
||||
results.append(False)
|
||||
|
||||
return all(results)
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("🧪 Testing Blockchain RPC...")
|
||||
|
||||
connection_ok = test_rpc_connection()
|
||||
methods_ok = test_rpc_methods()
|
||||
|
||||
if connection_ok and methods_ok:
|
||||
print("✅ Blockchain RPC tests passed")
|
||||
else:
|
||||
print("❌ Blockchain RPC tests failed")
|
||||
EOF
|
||||
echo 'import requests' > test_blockchain_rpc.py
|
||||
echo 'import json' >> test_blockchain_rpc.py
|
||||
echo '' >> test_blockchain_rpc.py
|
||||
echo 'def test_rpc_connection():' >> test_blockchain_rpc.py
|
||||
echo ' try:' >> test_blockchain_rpc.py
|
||||
echo ' payload = {' >> test_blockchain_rpc.py
|
||||
echo ' "jsonrpc": "2.0",' >> test_blockchain_rpc.py
|
||||
echo ' "method": "eth_blockNumber",' >> test_blockchain_rpc.py
|
||||
echo ' "params": [],' >> test_blockchain_rpc.py
|
||||
echo ' "id": 1' >> test_blockchain_rpc.py
|
||||
echo ' }' >> test_blockchain_rpc.py
|
||||
echo ' response = requests.post('"'"'http://localhost:8545'"'"', json=payload, timeout=5)' >> test_blockchain_rpc.py
|
||||
echo ' if response.status_code == 200:' >> test_blockchain_rpc.py
|
||||
echo ' result = response.json()' >> test_blockchain_rpc.py
|
||||
echo ' print(f"✅ RPC connection: {result.get('"'"'result'"'"', '"'"'Unknown block number'"'"')}")' >> test_blockchain_rpc.py
|
||||
echo ' return True' >> test_blockchain_rpc.py
|
||||
echo ' else:' >> test_blockchain_rpc.py
|
||||
echo ' print(f"❌ RPC connection failed: {response.status_code}")' >> test_blockchain_rpc.py
|
||||
echo ' return False' >> test_blockchain_rpc.py
|
||||
echo ' except Exception as e:' >> test_blockchain_rpc.py
|
||||
echo ' print(f"❌ RPC connection error: {e}")' >> test_blockchain_rpc.py
|
||||
echo ' return False' >> test_blockchain_rpc.py
|
||||
echo '' >> test_blockchain_rpc.py
|
||||
echo 'def test_rpc_methods():' >> test_blockchain_rpc.py
|
||||
echo ' methods = [' >> test_blockchain_rpc.py
|
||||
echo ' {"method": "eth_getBalance", "params": ["0x0000000000000000000000000000000000000000", "latest"]},' >> test_blockchain_rpc.py
|
||||
echo ' {"method": "eth_chainId", "params": []},' >> test_blockchain_rpc.py
|
||||
echo ' {"method": "eth_gasPrice", "params": []}' >> test_blockchain_rpc.py
|
||||
echo ' ]' >> test_blockchain_rpc.py
|
||||
echo ' ' >> test_blockchain_rpc.py
|
||||
echo ' results = []' >> test_blockchain_rpc.py
|
||||
echo ' for method in methods:' >> test_blockchain_rpc.py
|
||||
echo ' try:' >> test_blockchain_rpc.py
|
||||
echo ' payload = {' >> test_blockchain_rpc.py
|
||||
echo ' "jsonrpc": "2.0",' >> test_blockchain_rpc.py
|
||||
echo ' "method": method["method"],' >> test_blockchain_rpc.py
|
||||
echo ' "params": method["params"],' >> test_blockchain_rpc.py
|
||||
echo ' "id": 1' >> test_blockchain_rpc.py
|
||||
echo ' }' >> test_blockchain_rpc.py
|
||||
echo ' response = requests.post('"'"'http://localhost:8545'"'"', json=payload, timeout=5)' >> test_blockchain_rpc.py
|
||||
echo ' if response.status_code == 200:' >> test_blockchain_rpc.py
|
||||
echo ' result = response.json()' >> test_blockchain_rpc.py
|
||||
echo ' print(f"✅ {method['"'"'method'"'"']}: {result.get('"'"'result'"'"', '"'"'Success'"'"')}")' >> test_blockchain_rpc.py
|
||||
echo ' results.append(True)' >> test_blockchain_rpc.py
|
||||
echo ' else:' >> test_blockchain_rpc.py
|
||||
echo ' print(f"❌ {method['"'"'method'"'"']}: {response.status_code}")' >> test_blockchain_rpc.py
|
||||
echo ' results.append(False)' >> test_blockchain_rpc.py
|
||||
echo ' except Exception as e:' >> test_blockchain_rpc.py
|
||||
echo ' print(f"❌ {method['"'"'method'"'"']}: {e}")' >> test_blockchain_rpc.py
|
||||
echo ' results.append(False)' >> test_blockchain_rpc.py
|
||||
echo ' ' >> test_blockchain_rpc.py
|
||||
echo ' return all(results)' >> test_blockchain_rpc.py
|
||||
echo '' >> test_blockchain_rpc.py
|
||||
echo 'if __name__ == "__main__":' >> test_blockchain_rpc.py
|
||||
echo ' print("🧪 Testing Blockchain RPC...")' >> test_blockchain_rpc.py
|
||||
echo ' ' >> test_blockchain_rpc.py
|
||||
echo ' connection_ok = test_rpc_connection()' >> test_blockchain_rpc.py
|
||||
echo ' methods_ok = test_rpc_methods()' >> test_blockchain_rpc.py
|
||||
echo ' ' >> test_blockchain_rpc.py
|
||||
echo ' if connection_ok and methods_ok:' >> test_blockchain_rpc.py
|
||||
echo ' print("✅ Blockchain RPC tests passed")' >> test_blockchain_rpc.py
|
||||
echo ' else:' >> test_blockchain_rpc.py
|
||||
echo ' print("❌ Blockchain RPC tests failed")' >> test_blockchain_rpc.py
|
||||
|
||||
python test_blockchain_rpc.py
|
||||
|
||||
@@ -422,60 +414,58 @@ EOF
|
||||
echo "⚡ Testing API performance..."
|
||||
|
||||
# Create performance test
|
||||
cat > test_api_performance.py << 'EOF'
|
||||
import requests
|
||||
import time
|
||||
import statistics
|
||||
|
||||
def measure_response_time(url, timeout=5):
|
||||
try:
|
||||
start_time = time.time()
|
||||
response = requests.get(url, timeout=timeout)
|
||||
end_time = time.time()
|
||||
return end_time - start_time, response.status_code
|
||||
except Exception as e:
|
||||
return None, str(e)
|
||||
|
||||
def test_api_performance():
|
||||
apis = [
|
||||
("Coordinator API", "http://localhost:8000/"),
|
||||
("Exchange API", "http://localhost:8001/"),
|
||||
("Wallet API", "http://localhost:8002/"),
|
||||
("Blockchain RPC", "http://localhost:8545")
|
||||
]
|
||||
|
||||
for name, url in apis:
|
||||
print(f"\n📊 Testing {name} performance...")
|
||||
|
||||
times = []
|
||||
success_count = 0
|
||||
|
||||
for i in range(10):
|
||||
response_time, status = measure_response_time(url)
|
||||
if response_time is not None:
|
||||
times.append(response_time)
|
||||
if status == 200:
|
||||
success_count += 1
|
||||
print(f" Request {i+1}: {response_time:.3f}s (status: {status})")
|
||||
else:
|
||||
print(f" Request {i+1}: Failed ({status})")
|
||||
|
||||
if times:
|
||||
avg_time = statistics.mean(times)
|
||||
min_time = min(times)
|
||||
max_time = max(times)
|
||||
|
||||
print(f" 📈 Average: {avg_time:.3f}s")
|
||||
print(f" 📉 Min: {min_time:.3f}s")
|
||||
print(f" 📈 Max: {max_time:.3f}s")
|
||||
print(f" ✅ Success rate: {success_count}/10")
|
||||
else:
|
||||
print(f" ❌ All requests failed")
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("⚡ Testing API performance...")
|
||||
test_api_performance()
|
||||
EOF
|
||||
echo 'import requests' > test_api_performance.py
|
||||
echo 'import time' >> test_api_performance.py
|
||||
echo 'import statistics' >> test_api_performance.py
|
||||
echo '' >> test_api_performance.py
|
||||
echo 'def measure_response_time(url, timeout=5):' >> test_api_performance.py
|
||||
echo ' try:' >> test_api_performance.py
|
||||
echo ' start_time = time.time()' >> test_api_performance.py
|
||||
echo ' response = requests.get(url, timeout=timeout)' >> test_api_performance.py
|
||||
echo ' end_time = time.time()' >> test_api_performance.py
|
||||
echo ' return end_time - start_time, response.status_code' >> test_api_performance.py
|
||||
echo ' except Exception as e:' >> test_api_performance.py
|
||||
echo ' return None, str(e)' >> test_api_performance.py
|
||||
echo '' >> test_api_performance.py
|
||||
echo 'def test_api_performance():' >> test_api_performance.py
|
||||
echo ' apis = [' >> test_api_performance.py
|
||||
echo ' ("Coordinator API", "http://localhost:8000/"),' >> test_api_performance.py
|
||||
echo ' ("Exchange API", "http://localhost:8001/"),' >> test_api_performance.py
|
||||
echo ' ("Wallet API", "http://localhost:8002/"),' >> test_api_performance.py
|
||||
echo ' ("Blockchain RPC", "http://localhost:8545")' >> test_api_performance.py
|
||||
echo ' ]' >> test_api_performance.py
|
||||
echo ' ' >> test_api_performance.py
|
||||
echo ' for api_name, api_url in apis:' >> test_api_performance.py
|
||||
echo ' print(f"🧪 Testing {api_name} performance...")' >> test_api_performance.py
|
||||
echo ' ' >> test_api_performance.py
|
||||
echo ' times = []' >> test_api_performance.py
|
||||
echo ' success_count = 0' >> test_api_performance.py
|
||||
echo ' ' >> test_api_performance.py
|
||||
echo ' for i in range(10):' >> test_api_performance.py
|
||||
echo ' response_time, status = measure_response_time(api_url)' >> test_api_performance.py
|
||||
echo ' if response_time is not None:' >> test_api_performance.py
|
||||
echo ' times.append(response_time)' >> test_api_performance.py
|
||||
echo ' if status == 200:' >> test_api_performance.py
|
||||
echo ' success_count += 1' >> test_api_performance.py
|
||||
echo ' print(f" Request {i+1}: {response_time:.3f}s (status: {status})")' >> test_api_performance.py
|
||||
echo ' else:' >> test_api_performance.py
|
||||
echo ' print(f" Request {i+1}: Failed ({status})")' >> test_api_performance.py
|
||||
echo ' ' >> test_api_performance.py
|
||||
echo ' if times:' >> test_api_performance.py
|
||||
echo ' avg_time = statistics.mean(times)' >> test_api_performance.py
|
||||
echo ' min_time = min(times)' >> test_api_performance.py
|
||||
echo ' max_time = max(times)' >> test_api_performance.py
|
||||
echo ' ' >> test_api_performance.py
|
||||
echo ' print(f" 📈 Average: {avg_time:.3f}s")' >> test_api_performance.py
|
||||
echo ' print(f" 📉 Min: {min_time:.3f}s")' >> test_api_performance.py
|
||||
echo ' print(f" 📈 Max: {max_time:.3f}s")' >> test_api_performance.py
|
||||
echo ' print(f" ✅ Success rate: {success_count}/10")' >> test_api_performance.py
|
||||
echo ' else:' >> test_api_performance.py
|
||||
echo ' print(f" ❌ All requests failed")' >> test_api_performance.py
|
||||
echo '' >> test_api_performance.py
|
||||
echo 'if __name__ == "__main__":' >> test_api_performance.py
|
||||
echo ' print("⚡ Testing API performance...")' >> test_api_performance.py
|
||||
echo ' test_api_performance()' >> test_api_performance.py
|
||||
|
||||
python test_api_performance.py
|
||||
|
||||
|
||||
Reference in New Issue
Block a user