| |
| |
|
|
| import http from 'k6/http'; |
| import { check } from 'k6'; |
|
|
| |
| export const BASE_URL = __ENV.API_URL || 'http://localhost:8000'; |
|
|
| |
| export const BASE_THRESHOLDS = { |
| http_req_duration: ['p(95)<500', 'p(99)<1000'], |
| http_req_failed: ['rate<0.05'], |
| }; |
|
|
| |
| export function login() { |
| const loginPayload = JSON.stringify({ |
| email: 'load_test@example.com', |
| password: 'test_password_123' |
| }); |
|
|
| const params = { |
| headers: { |
| 'Content-Type': 'application/json', |
| }, |
| }; |
|
|
| const response = http.post(`${BASE_URL}/api/auth/login`, loginPayload, params); |
|
|
| check(response, { |
| 'login successful': (r) => r.status === 200, |
| 'received token': (r) => r.json('token') !== undefined, |
| }); |
|
|
| return response.json('token'); |
| } |
|
|
| |
| export function getAuthHeaders(token) { |
| return { |
| headers: { |
| 'Content-Type': 'application/json', |
| 'Authorization': `Bearer ${token}`, |
| }, |
| }; |
| } |
|
|
| |
| export function getRandomUser() { |
| const users = [ |
| { email: 'load_test@example.com', password: 'test_password_123' }, |
| { email: 'user1@example.com', password: 'password123' }, |
| { email: 'user2@example.com', password: 'password123' }, |
| ]; |
| return users[Math.floor(Math.random() * users.length)]; |
| } |
|
|
| |
| export function executeAgent(token, agentId = null) { |
| const id = agentId || 'test-agent-' + Math.floor(Math.random() * 1000); |
| const payload = JSON.stringify({ |
| query: 'Hello, this is a test query', |
| agent_id: id, |
| }); |
|
|
| const params = getAuthHeaders(token); |
| const response = http.post(`${BASE_URL}/api/v1/agents/execute`, payload, params); |
|
|
| check(response, { |
| 'agent execution started': (r) => r.status === 200 || r.status === 202, |
| }); |
|
|
| return response; |
| } |
|
|
| |
| export function getAgents(token) { |
| const params = getAuthHeaders(token); |
| const response = http.get(`${BASE_URL}/api/v1/agents`, params); |
|
|
| check(response, { |
| 'agents list retrieved': (r) => r.status === 200, |
| }); |
|
|
| return response; |
| } |
|
|
| |
| export function getCanvas(token, canvasId) { |
| const params = getAuthHeaders(token); |
| const response = http.get(`${BASE_URL}/api/v1/canvas/${canvasId}`, params); |
|
|
| check(response, { |
| 'canvas retrieved': (r) => r.status === 200 || r.status === 404, |
| }); |
|
|
| return response; |
| } |
|
|
| |
| export function presentCanvas(token, canvasId) { |
| const payload = JSON.stringify({ |
| canvas_id: canvasId, |
| }); |
|
|
| const params = getAuthHeaders(token); |
| const response = http.post(`${BASE_URL}/api/v1/canvas/present`, payload, params); |
|
|
| check(response, { |
| 'canvas presentation started': (r) => r.status === 200 || r.status === 202, |
| }); |
|
|
| return response; |
| } |
|
|
| |
| export const options = { |
| thresholds: BASE_THRESHOLDS, |
| }; |
|
|