diff --git a/.gitea/workflows/api-endpoint-tests.yml b/.gitea/workflows/api-endpoint-tests.yml index a45aa91d..0214316e 100644 --- a/.gitea/workflows/api-endpoint-tests.yml +++ b/.gitea/workflows/api-endpoint-tests.yml @@ -414,60 +414,58 @@ jobs: 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