import http from 'k6/http' import { check, sleep } from 'k6' export const options = { vus: 30, duration: '45s', thresholds: { http_req_failed: ['rate<0.01'], http_req_duration: ['p(95)<800'] } } const baseUrl = __ENV.BASE_URL || 'http://localhost:8080' function token() { const res = http.post(`${baseUrl}/api/v1/auth/login`, JSON.stringify({ username: 'hr_admin', password: 'ChangeMe123!' }), { headers: { 'Content-Type': 'application/json' } }) return res.json('data.accessToken') } export default function () { const res = http.get(`${baseUrl}/api/v1/employees?page=1&size=20&keyword=员工`, { headers: { Authorization: `Bearer ${token()}` } }) check(res, { 'search ok': (r) => r.status === 200 }) sleep(1) }