From 57544ee047076fdf1af8b5c70669c63040b5299c Mon Sep 17 00:00:00 2001 From: Aanya Date: Fri, 12 Jun 2026 20:29:23 +0530 Subject: [PATCH] feat: add load testing infrastructure with Locust --- requirements-dev.txt | 3 ++- tests/load/README.md | 58 ++++++++++++++++++++++++++++++++++++++++ tests/load/locustfile.py | 56 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 tests/load/README.md create mode 100644 tests/load/locustfile.py diff --git a/requirements-dev.txt b/requirements-dev.txt index dc80d28..77d7496 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -27,4 +27,5 @@ watchdog>=6.0.0 # Type Stubs types-requests>=2.31.0 -types-redis>=4.6.0.20241004 \ No newline at end of file +types-redis>=4.6.0.20241004 +locust>=2.31.0 \ No newline at end of file diff --git a/tests/load/README.md b/tests/load/README.md new file mode 100644 index 0000000..f2e5c8e --- /dev/null +++ b/tests/load/README.md @@ -0,0 +1,58 @@ +# TENET AI Load Testing + +## Overview + +This directory contains load testing scripts for TENET AI APIs using Locust. + +## Tested Endpoints + +- GET /health +- GET /v1/stats +- GET /v1/events +- POST /v1/events/llm + +## Installation + +```bash +pip install locust +``` + +## Running Tests + +```bash +locust -f tests/load/locustfile.py +``` + +Then open: + +http://localhost:8089 + +## Test Scenarios + +### Sustained Load Test + +- Target: 100 requests/second +- Duration: 10 minutes + +### Spike Load Test + +- Simulate sudden bursts of traffic +- Increase users rapidly + +### Concurrent Connection Test + +- Run multiple concurrent users +- Observe latency and error rates + +## Metrics to Measure + +- P50 latency +- P95 latency +- P99 latency +- Throughput +- Error rate + +## Acceptance Criteria + +- P95 latency < 500 ms under sustained load +- Error rate < 0.1% under normal load \ No newline at end of file diff --git a/tests/load/locustfile.py b/tests/load/locustfile.py new file mode 100644 index 0000000..e5f9c1e --- /dev/null +++ b/tests/load/locustfile.py @@ -0,0 +1,56 @@ +from locust import HttpUser, task, between + +API_KEY = "test-api-key" + + +class TENETLoadUser(HttpUser): + wait_time = between(1, 3) + + headers = { + "x-api-key": API_KEY, + "Content-Type": "application/json", + } + + @task(3) + def health_check(self): + self.client.get( + "/health", + headers=self.headers, + name="GET /health" + ) + + @task(2) + def get_stats(self): + self.client.get( + "/v1/stats", + headers=self.headers, + name="GET /v1/stats" + ) + + @task(2) + def list_events(self): + self.client.get( + "/v1/events", + headers=self.headers, + name="GET /v1/events" + ) + + @task(1) + def submit_llm_event(self): + payload = { + "source_type": "chat", + "source_id": "load-test-user", + "model": "gpt-4", + "prompt": "This is a load testing request", + "system_prompt": "You are a helpful assistant", + "metadata": { + "environment": "load-test" + } + } + + self.client.post( + "/v1/events/llm", + json=payload, + headers=self.headers, + name="POST /v1/events/llm" + ) \ No newline at end of file