import http from 'k6/http'; import { check, sleep } from 'k6'; import { Rate, Trend } from 'k6/metrics'; const BASE_URL = __ENV.BASE_URL || 'http://localhost:8080'; const payloads = [ 'Клиент Иванов Иван Иванович, паспорт 4509 123456, тел +7 916 123-45-67', 'Заявление от И.И. Петрова, ИНН 770301234550, почта ivan.petrov@mail.ru', 'Адрес: 125009, г. Москва, ул. Тверская, д. 7, кв. 15, карта 4111 1111 1111 1111', 'Дата рождения 12.05.1985, место рождения: город Тверь, гражданство РФ', 'Напиши краткое описание продукта для рассылки клиентам банка', ]; const errorRate = new Rate('http_req_failed'); const latency = new Trend('latency_ms', true); export const options = { scenarios: { load: { executor: 'ramping-vus', startVUs: 0, stages: [ { duration: '30s', target: 500 }, { duration: '30s', target: 1000 }, { duration: '30s', target: 1500 }, { duration: '30s', target: 2000 }, { duration: '30s', target: 0 }, ], }, }, thresholds: { http_req_failed: ['rate<0.01'], http_req_duration: ['p(95)<200'], }, }; export default function () { const body = JSON.stringify({ payload: payloads[Math.floor(Math.random() * payloads.length)], payload_id: `k6-${__VU}-${__ITER}`, }); const res = http.post(`${BASE_URL}/process`, body, { headers: { 'Content-Type': 'application/json', 'X-System-Id': 'crm', }, }); latency.add(res.timings.duration); check(res, { 'status is 200': (r) => r.status === 200, 'has result': (r) => r.json('result') !== undefined, }); sleep(0.1); }