Commit 471e3999 authored by Wade's avatar Wade

add test

parent 72dfd873
import random
import uuid
from locust import HttpUser, task, between
class ChatUser(HttpUser):
# Wait between 1 and 5 seconds between requests
wait_time = between(1, 5)
# Define the host (can be overridden in Locust UI or environment)
host = "http://54.92.111.204:8000"
@task
def post_chat(self):
# Define possible values for dynamic fields
questions = [
"What is the capital of UK?",
"Who is the president of the USA?",
"What is the largest planet in our solar system?",
"What is the boiling point of water?",
"Who wrote 'Pride and Prejudice'?"
]
model_options = [
["deepseek/deepseek-chat"],
["ollama/llama3.1"],
["deepseek/deepseek-chat", "ollama/llama3.1"]
]
names = ["Alice", "Bob", "Charlie", "Diana", "Eve"]
boolean_options = [True, False]
# Generate request payload
payload = {
"content": random.choice(questions),
"models": random.choice(model_options),
"apiKey": f"sk-{uuid.uuid4().hex[:16]}",
"from": random.choice(names),
"from_id": f"user-{uuid.uuid4().hex[:8]}",
"to": random.choice(names),
"to_id": f"user-{uuid.uuid4().hex[:8]}",
"milvus": random.choice(boolean_options),
"graph": random.choice(boolean_options)
}
# Send POST request to /chat
headers = {
"accept": "application/json",
"Content-Type": "application/json"
}
with self.client.post(
"/chat",
json=payload,
headers=headers,
catch_response=True
) as response:
try:
# Parse response JSON
resp_json = response.json()
# Validate response
if resp_json.get("code") == 200 and resp_json.get("data"):
response.success()
else:
response.failure(f"Unexpected code: {resp_json.get('code', 'N/A')} - {resp_json.get('msg', 'No message')}")
except ValueError:
response.failure(f"Invalid JSON response: {response.text}")
except Exception as e:
response.failure(f"Error: {str(e)}")
\ No newline at end of file
version: '3.8'
services:
web:
image: python:3.9-slim
container_name: web_app
command: >
sh -c "pip install psycopg2-binary &&
python -m http.server 8000"
volumes:
- ./app:/app
working_dir: /app
locust:
image: locustio/locust:latest
container_name: locust
ports:
- "8000:8000"
depends_on:
- db
- "8089:8089" # Expose Locust web UI
volumes:
- ./config/test/locustfile.py:/mnt/locust/locustfile.py # Mount the Locust script
environment:
- DB_HOST=db
- DB_NAME=mydatabase
- DB_USER=myuser
- DB_PASSWORD=mypassword
networks:
- app_network
extends:
file: docker-compose.db.yml
service: db
networks:
app_network:
driver: bridge
# version: '3.9'
# services:
# agentchat:
# container_name: "agentchat"
# build:
# context: . # Build context is the current directory
# dockerfile: Dockerfile # Dockerfile for agentchat
# volumes:
# - /var/log:/var/log
# environment:
# - GEMINI_API_KEY=${GEMINI_API_KEY} # Reference variable from .env
# ports:
# - "8000:8000"
# entrypoint: /app/myapp
# docker-host:
# image: qoomon/docker-host
# cap_add: ['NET_ADMIN', 'NET_RAW']
# mem_limit: 8M
# restart: on-failure
# # etcd:
# # container_name: milvus-etcd
# # image: quay.io/coreos/etcd:v3.5.18
# # environment:
# # - ETCD_AUTO_COMPACTION_MODE=revision
# # - ETCD_AUTO_COMPACTION_RETENTION=1000
# # - ETCD_QUOTA_BACKEND_BYTES=4294967296
# # - ETCD_SNAPSHOT_COUNT=50000
# # volumes:
# # - ${DOCKER_VOLUME_DIRECTORY:-.}/volumes/etcd:/etcd
# # command: etcd -advertise-client-urls=http://etcd:2379 -listen-client-urls http://0.0.0.0:2379 --data-dir /etcd
# # healthcheck:
# # test: ["CMD", "etcdctl", "endpoint", "health"]
# # interval: 30s
# # timeout: 20s
# # retries: 3
# # minio:
# # container_name: milvus-minio
# # image: minio/minio:RELEASE.2023-03-20T20-16-18Z
# # environment:
# # MINIO_ACCESS_KEY: minioadmin
# # MINIO_SECRET_KEY: minioadmin
# # ports:
# # - "9001:9001"
# # - "9000:9000"
# # volumes:
# # - ${DOCKER_VOLUME_DIRECTORY:-.}/volumes/minio:/minio_data
# # command: minio server /minio_data --console-address ":9001"
# # healthcheck:
# # test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
# # interval: 30s
# # timeout: 20s
# # retries: 3
# # standalone:
# # container_name: milvus-standalone
# # image: milvusdb/milvus:v2.5.10
# # command: ["milvus", "run", "standalone"]
# # security_opt:
# # - seccomp:unconfined
# # environment:
# # ETCD_ENDPOINTS: etcd:2379
# # MINIO_ADDRESS: minio:9000
# # volumes:
# # - ${DOCKER_VOLUME_DIRECTORY:-.}/volumes/milvus:/var/lib/milvus
# # healthcheck:
# # test: ["CMD", "curl", "-f", "http://localhost:9091/healthz"]
# # interval: 30s
# # start_period: 90s
# # timeout: 20s
# # retries: 3
# # ports:
# # - "19530:19530"
# # - "9091:9091"
# # depends_on:
# # - "etcd"
# # - "minio"
# # db:
# # image: mysql/mysql-server
# # environment:
# # MYSQL_USER: 'user'
# # MYSQL_PASSWORD: 'password'
# # MYSQL_ROOT_PASSWORD: 'aa123456'
# # ports:
# # - 3306:3306
# # volumes:
# # - dbgpt-myql-db:/var/lib/mysql
# # - ./docker/examples/my.cnf:/etc/my.cnf
# # - ./docker/examples/sqls:/docker-entrypoint-initdb.d
# # - ./assets/schema/dbgpt.sql:/docker-entrypoint-initdb.d/dbgpt.sql
# # restart: unless-stopped
# # webserver:
# # image: eosphorosai/dbgpt-openai:latest
# # command: dbgpt start webserver --config /app/configs/dbgpt-graphrag.toml
# # environment:
# # - SILICONFLOW_API_KEY=${SILICONFLOW_API_KEY}
# # - MYSQL_PASSWORD=aa123456
# # - MYSQL_HOST=db
# # - MYSQL_PORT=3306
# # - MYSQL_DATABASE=dbgpt
# # - MYSQL_USER=root
# # - OPENAI_API_KEY=sk-UIpD9DohtE0Ok4wtFdC21668Dc3241629e8aA05d5dAeFdA1
# # volumes:
# # - ./configs:/app/configs
# # - /data:/data
# # # May be you can mount your models to container
# # - /data/models:/app/models
# # - dbgpt-data:/app/pilot/data
# # - dbgpt-message:/app/pilot/message
# # depends_on:
# # - db
# # - tugraph
# # ports:
# # - 5670:5670/tcp
# # # webserver may be failed, it must wait all sqls in /docker-entrypoint-initdb.d execute finish.
# # restart: unless-stopped
# # networks:
# # - dbgptnet
# # ipc: host
# # tugraph:
# # image: tugraph/tugraph-runtime-centos7:4.5.1
# # command: lgraph_server -d run --enable_plugin true
# # ports:
# # - 7070:7070
# # - 7687:7687
# # - 9090:9090
# # container_name: tugraph_demo
# # restart: unless-stopped
# # volumes:
# # dbgpt-myql-db:
# # dbgpt-data:
# # dbgpt-message:
# # dbgpt-alembic-versions:
- LOCUST_HOST=http://agentchat:8000 # Replace with your API server host
command: -f /mnt/locust/locustfile.py --master
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment