import http from 'k6/http';
import { check, sleep } from 'k6';
export const options = {
stages: [
{ duration: '2m', target: 50 }, // 爬坡
{ duration: '5m', target: 50 }, // 稳定
{ duration: '2m', target: 100 }, // 继续增加
{ duration: '5m', target: 100 }, // 稳定
{ duration: '2m', target: 0 }, // 降低
],
thresholds: {
http_req_duration: ['p(95)<500', 'p(99)<1000'], // 95 百分位 < 500ms
http_req_failed: ['rate<0.01'], // 错误率 < 1%
},
};
export default function () {
const res = http.post('https://api.example.com/auth/login', {
email: '
[email protected]',
password: 'password123',
});
check(res, {
'状态码 200': (r) => r.status === 200,
'有 token': (r) => r.json('token') !== undefined,
});
sleep(1); // 思考时间
}