import http from 'k6/http'; import { check, sleep } from 'k6'; /** * ST-BOT-03 — Storm de eventos sobre un job existente. * * k6 run -e DOWNLOAD_JOB_ID= -e PROFILE=shared8g k6_bot_events.js */ const PROFILE = __ENV.PROFILE || 'shared8g'; const BASE_URL = __ENV.BASE_URL || 'http://127.0.0.1:8189'; const TOKEN = __ENV.BOT_API_TOKEN || 'dev-token-change-me'; const JOB_ID = __ENV.DOWNLOAD_JOB_ID || ''; const profiles = { shared8g: { stages: [ { duration: '15s', target: 5 }, { duration: '45s', target: 12 }, { duration: '15s', target: 0 }, ], }, lab: { stages: [ { duration: '20s', target: 10 }, { duration: '1m', target: 40 }, { duration: '20s', target: 0 }, ], }, }; const cfg = profiles[PROFILE] || profiles.shared8g; export const options = { stages: cfg.stages, thresholds: { http_req_failed: ['rate<0.02'], http_req_duration: ['p(95)<1000'], }, tags: { profile: PROFILE }, }; export default function () { if (!JOB_ID) { throw new Error('Defina DOWNLOAD_JOB_ID con un job existente'); } const idx = __ITER + 1; const payload = JSON.stringify({ event_type: 'progress', message: `k6 event ${idx}`, index: idx, total: 5000, radicado: `R-${idx}`, nit: '900123456', metadata: { source: 'k6', profile: PROFILE }, }); const res = http.post(`${BASE_URL}/bot-descarga/jobs/${JOB_ID}/events`, payload, { headers: { Authorization: `Bearer ${TOKEN}`, 'Content-Type': 'application/json', }, }); check(res, { 'event accepted': (r) => r.status === 200, }); sleep(PROFILE === 'shared8g' ? 0.15 : 0.05); }