import http from 'k6/http'; import { check, sleep } from 'k6'; const API = 'http://172.31.12.249:18080/api/hss'; const H = { 'Content-Type': 'application/json', 'X-Tenant-Id': '1', 'X-Org-Id': '1', 'X-User-Role': 'ADMIN' }; // Stress test: 50 concurrent users creating applications export const options = { scenarios: { create_applications: { executor: 'constant-arrival-rate', rate: 10, // 10 requests per second timeUnit: '1s', duration: '30s', preAllocatedVUs: 50, maxVUs: 100, }, }, thresholds: { http_req_duration: ['p(95)<3000', 'p(99)<5000'], http_req_failed: ['rate<0.10'], }, }; export default function () { const idemKey = 'stress-' + __VU + '-' + __ITER + '-' + Date.now(); const r = http.post(API + '/applications', JSON.stringify({ patientId: '2001', serviceType: 'HOME_CARE', channel: 'WECHAT', contactName: 'Stress', contactPhone: '13800000000', address: '梅江区', regionCode: '441402001' }), { headers: { ...H, 'Idempotency-Key': idemKey } }); check(r, { 'create 200': (r) => r.status === 200 }); }