The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
add toxi proxy tests to ci/cd
Ishaan Jaffc6d5793bf607
diff --git a/.circleci/config.yml b/.circleci/config.ymlindex b93a9d81e8e..87432c7a248 100644--- a/.circleci/config.yml+++ b/.circleci/config.yml@@ -470,6 +470,61 @@ jobs:paths:- litellm_proxy_security_tests_coverage.xml- litellm_proxy_security_tests_coverage+ litellm_proxy_reliability_tests:+ docker:+ - image: cimg/python:3.11+ auth:+ username: ${DOCKERHUB_USERNAME}+ password: ${DOCKERHUB_PASSWORD}+ working_directory: ~/project+ steps:+ - checkout+ - run:+ name: Show git commit hash+ command: |+ echo "Git commit hash: $CIRCLE_SHA1"+ - run:+ name: Install Dependencies+ command: |+ python -m pip install --upgrade pip+ python -m pip install -r requirements.txt+ pip install "requests==2.31.0"+ pip install "pytest==7.3.1"+ pip install "pytest-retry==1.6.3"+ pip install "pytest-asyncio==0.21.1"+ pip install "pytest-cov==5.0.0"+ - run:+ name: Setup Toxiproxy+ command: |+ python tests/proxy_reliability_tests/setup_toxiproxy.py+ - run:+ name: Run prisma ./docker/entrypoint.sh+ command: |+ set +e+ chmod +x docker/entrypoint.sh+ ./docker/entrypoint.sh+ set -e+ # Run pytest and generate JUnit XML report+ - run:+ name: Run tests+ command: |+ pwd+ ls+ python -m pytest tests/proxy_security_tests --cov=litellm --cov-report=xml -vv -x -v --junitxml=test-results/junit.xml --durations=5+ no_output_timeout: 120m+ - run:+ name: Rename the coverage files+ command: |+ mv coverage.xml litellm_proxy_security_tests_coverage.xml+ mv .coverage litellm_proxy_security_tests_coverage+ # Store test results+ - store_test_results:+ path: test-results+ - persist_to_workspace:+ root: .+ paths:+ - litellm_proxy_security_tests_coverage.xml+ - litellm_proxy_security_tests_coveragelitellm_proxy_unit_testing: # Runs all tests with the "proxy", "key", "jwt" filenamesdocker:- image: cimg/python:3.11@@ -2451,6 +2506,12 @@ workflows:only:- main- /litellm_.*/+ - litellm_proxy_reliability_tests:+ filters:+ branches:+ only:+ - main+ - /litellm_.*/- litellm_assistants_api_testing:filters:branches:@@ -2592,6 +2653,7 @@ workflows:- caching_unit_tests- litellm_proxy_unit_testing- litellm_proxy_security_tests+ - litellm_proxy_reliability_tests- langfuse_logging_unit_tests- local_testing- litellm_assistants_api_testing@@ -2657,6 +2719,7 @@ workflows:- e2e_ui_testing- litellm_proxy_unit_testing- litellm_proxy_security_tests+ - litellm_proxy_reliability_tests- installing_litellm_on_python- installing_litellm_on_python_3_13- proxy_logging_guardrails_model_info_testsdiff --git a/tests/proxy_reliability_tests/setup_toxi_proxy.py b/tests/proxy_reliability_tests/setup_toxi_proxy.pynew file mode 100644index 00000000000..3625b0bd3a2--- /dev/null+++ b/tests/proxy_reliability_tests/setup_toxi_proxy.py@@ -0,0 +1,96 @@+import os+import platform+import subprocess+import time+import requests+import stat+++def download_toxiproxy():+ # Determine system architecture and OS+ system = platform.system().lower()+ machine = platform.machine().lower()++ # Map architecture names+ arch_map = {+ "x86_64": "amd64",+ "amd64": "amd64",+ "arm64": "arm64",+ "aarch64": "arm64",+ }++ arch = arch_map.get(machine, machine)++ # Construct download URL (using latest version 2.5.0)+ base_url = "https://github.com/Shopify/toxiproxy/releases/download/v2.5.0/"+ if system == "linux":+ filename = f"toxiproxy-server-linux-{arch}"+ cli_filename = f"toxiproxy-cli-linux-{arch}"+ elif system == "darwin":+ filename = f"toxiproxy-server-darwin-{arch}"+ cli_filename = f"toxiproxy-cli-darwin-{arch}"+ else:+ raise Exception("Unsupported operating system")++ # Download server+ response = requests.get(f"{base_url}{filename}")+ with open("toxiproxy-server", "wb") as f:+ f.write(response.content)++ # Download CLI+ response = requests.get(f"{base_url}{cli_filename}")+ with open("toxiproxy-cli", "wb") as f:+ f.write(response.content)++ # Make files executable+ os.chmod("toxiproxy-server", stat.S_IRWXU)+ os.chmod("toxiproxy-cli", stat.S_IRWXU)+++def setup_toxiproxy():+ # Start toxiproxy-server+ server_process = subprocess.Popen(["./toxiproxy-server"])++ # Wait for server to start+ time.sleep(2)++ # Create proxy+ subprocess.run(+ [+ "./toxiproxy-cli",+ "create",+ "postgres_proxy",+ "-l",+ "127.0.0.1:6666",+ "-u",+ "ep-dry-paper-a69g2y1q-pooler.us-west-2.aws.neon.tech:5432",+ ]+ )++ return server_process+++def main():+ try:+ # Download ToxiProxy binaries+ download_toxiproxy()++ # Setup ToxiProxy+ server_process = setup_toxiproxy()++ print("ToxiProxy setup completed successfully!")+ print("Proxy 'postgres_proxy' created and listening on 127.0.0.1:6666")++ # Keep the script running to maintain the proxy+ try:+ server_process.wait()+ except KeyboardInterrupt:+ server_process.terminate()+ print("\nToxiProxy server stopped")++ except Exception as e:+ print(f"Error: {e}")+++if __name__ == "__main__":+ main()