File size: 3,208 Bytes
aef804e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// k6 setup and configuration for Atom load testing
// This file provides base configuration and helper functions for all load tests

import http from 'k6/http';
import { check } from 'k6';

// Base URL configuration
export const BASE_URL = __ENV.API_URL || 'http://localhost:8000';

// Common thresholds configuration
export const BASE_THRESHOLDS = {
  http_req_duration: ['p(95)<500', 'p(99)<1000'],
  http_req_failed: ['rate<0.05'],
};

// Helper function for authentication
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');
}

// Helper function to create authenticated headers
export function getAuthHeaders(token) {
  return {
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${token}`,
    },
  };
}

// Helper function for random user selection
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)];
}

// Helper function for agent execution
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;
}

// Helper function for getting agents list
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;
}

// Helper function for canvas operations
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, // 404 is acceptable if canvas doesn't exist
  });

  return response;
}

// Helper function for presenting canvas
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 default options
export const options = {
  thresholds: BASE_THRESHOLDS,
};