login.js 562 B

123456789101112131415
  1. import http from 'k6/http'
  2. import { check, sleep } from 'k6'
  3. export const options = { vus: 20, duration: '30s', thresholds: { http_req_failed: ['rate<0.01'], http_req_duration: ['p(95)<1500'] } }
  4. const baseUrl = __ENV.BASE_URL || 'http://localhost:8080'
  5. export default function () {
  6. const res = http.post(`${baseUrl}/api/v1/auth/login`, JSON.stringify({
  7. username: 'sys_admin',
  8. password: 'ChangeMe123!',
  9. deviceName: 'k6'
  10. }), { headers: { 'Content-Type': 'application/json' } })
  11. check(res, { 'login ok': (r) => r.status === 200 })
  12. sleep(1)
  13. }